diff --git a/gnovm/pkg/gnolang/op_expressions.go b/gnovm/pkg/gnolang/op_expressions.go index 9d16941eefc..f35de3ded91 100644 --- a/gnovm/pkg/gnolang/op_expressions.go +++ b/gnovm/pkg/gnolang/op_expressions.go @@ -791,8 +791,7 @@ func (m *Machine) doOpConvert() { } else if t.Kind() == StringKind { // runes ([]int32) → string if st, ok := baseOf(xv.T).(*SliceType); ok && st.Elt.Kind() == Int32Kind { - sv := xv.V.(*SliceValue) - m.incrCPU(OpCPUSlopeConvertRunesStr * int64(sv.GetLength())) + m.incrCPU(OpCPUSlopeConvertRunesStr * int64(xv.GetLength())) } } } diff --git a/gnovm/tests/files/issue_5776.gno b/gnovm/tests/files/issue_5776.gno new file mode 100644 index 00000000000..dcb95e0b46a --- /dev/null +++ b/gnovm/tests/files/issue_5776.gno @@ -0,0 +1,18 @@ +// Test case where a slice of a user-defined byte type (not uint8 or byte) is +// converted to a string. Same for slice of runes. + +package main + +type MyByte byte + +type MyRune rune + +func main() { + var y []MyByte + _ = string(y) + + var z []MyRune + _ = string(z) +} + +// Output: