diff --git a/go/ssa/interp/interp_test.go b/go/ssa/interp/interp_test.go index 64ede78ae27..b3edc9916e2 100644 --- a/go/ssa/interp/interp_test.go +++ b/go/ssa/interp/interp_test.go @@ -129,6 +129,7 @@ var testdataTests = []string{ "width32.go", "fixedbugs/issue52342.go", + "fixedbugs/issue55115.go", } func init() { diff --git a/go/ssa/interp/ops.go b/go/ssa/interp/ops.go index dd309bf9ca9..65d6452b783 100644 --- a/go/ssa/interp/ops.go +++ b/go/ssa/interp/ops.go @@ -1211,8 +1211,7 @@ func conv(t_dst, t_src types.Type, x value) value { case *types.Slice: // []byte or []rune -> string - // TODO(adonovan): fix: type B byte; conv([]B -> string). - switch ut_src.Elem().(*types.Basic).Kind() { + switch ut_src.Elem().Underlying().(*types.Basic).Kind() { case types.Byte: x := x.([]value) b := make([]byte, 0, len(x)) @@ -1234,7 +1233,6 @@ func conv(t_dst, t_src types.Type, x value) value { x = widen(x) // integer -> string? - // TODO(adonovan): fix: test integer -> named alias of string. if ut_src.Info()&types.IsInteger != 0 { if ut_dst, ok := ut_dst.(*types.Basic); ok && ut_dst.Kind() == types.String { return fmt.Sprintf("%c", x) @@ -1246,8 +1244,7 @@ func conv(t_dst, t_src types.Type, x value) value { switch ut_dst := ut_dst.(type) { case *types.Slice: var res []value - // TODO(adonovan): fix: test named alias of rune, byte. - switch ut_dst.Elem().(*types.Basic).Kind() { + switch ut_dst.Elem().Underlying().(*types.Basic).Kind() { case types.Rune: for _, r := range []rune(s) { res = append(res, r) diff --git a/go/ssa/interp/testdata/fixedbugs/issue55115.go b/go/ssa/interp/testdata/fixedbugs/issue55115.go new file mode 100644 index 00000000000..0f856aeee0e --- /dev/null +++ b/go/ssa/interp/testdata/fixedbugs/issue55115.go @@ -0,0 +1,38 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "reflect" + +func main() { + type MyByte byte + type MyRune rune + type MyString string + + a := []MyByte{'a', 'b', 'c'} + if s := string(a); s != "abc" { + panic(s) + } + + b := []MyRune{'五', '五'} + if s := string(b); s != "五五" { + panic(s) + } + + c := []MyByte{'l', 'o', 'r', 'e', 'm'} + if s := MyString(c); s != MyString("lorem") { + panic(s) + } + + d := "lorem" + if a := []MyByte(d); !reflect.DeepEqual(a, []MyByte{'l', 'o', 'r', 'e', 'm'}) { + panic(a) + } + + e := 42 + if s := MyString(e); s != "*" { + panic(s) + } +}