compiler: fix named string to []byte slice conversion

This was missing a `.Underlying()` call to avoid testing the named type
(but instead test for the underlying type).
Этот коммит содержится в:
Ayke van Laethem 2020-07-27 12:35:29 +02:00 коммит произвёл Ron Evans
родитель e41e5106cc
коммит d4e04e4e49
2 изменённых файлов: 4 добавлений и 1 удалений

Просмотреть файл

@ -2536,7 +2536,7 @@ func (b *builder) createConvert(typeFrom, typeTo types.Type, value llvm.Value, p
return llvm.Value{}, b.makeError(pos, "todo: convert: basic non-integer type: "+typeFrom.String()+" -> "+typeTo.String())
case *types.Slice:
if basic, ok := typeFrom.(*types.Basic); !ok || basic.Info()&types.IsString == 0 {
if basic, ok := typeFrom.Underlying().(*types.Basic); !ok || basic.Info()&types.IsString == 0 {
panic("can only convert from a string to a slice")
}

3
testdata/string.go предоставленный
Просмотреть файл

@ -17,8 +17,11 @@ func testRunesToString(r []rune) {
println("string from runes:", string(r))
}
type myString string
func main() {
testRangeString()
testStringToRunes()
testRunesToString([]rune{97, 98, 99, 252, 162, 8364, 66376, 176, 120})
var _ = len([]byte(myString("foobar"))) // issue 1246
}