Skip to content

Commit d4e04e4

Browse files
aykevldeadprogram
authored andcommitted
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).
1 parent e41e510 commit d4e04e4

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

compiler/compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ func (b *builder) createConvert(typeFrom, typeTo types.Type, value llvm.Value, p
25362536
return llvm.Value{}, b.makeError(pos, "todo: convert: basic non-integer type: "+typeFrom.String()+" -> "+typeTo.String())
25372537

25382538
case *types.Slice:
2539-
if basic, ok := typeFrom.(*types.Basic); !ok || basic.Info()&types.IsString == 0 {
2539+
if basic, ok := typeFrom.Underlying().(*types.Basic); !ok || basic.Info()&types.IsString == 0 {
25402540
panic("can only convert from a string to a slice")
25412541
}
25422542

testdata/string.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ func testRunesToString(r []rune) {
1717
println("string from runes:", string(r))
1818
}
1919

20+
type myString string
21+
2022
func main() {
2123
testRangeString()
2224
testStringToRunes()
2325
testRunesToString([]rune{97, 98, 99, 252, 162, 8364, 66376, 176, 120})
26+
var _ = len([]byte(myString("foobar"))) // issue 1246
2427
}

0 commit comments

Comments
 (0)