Skip to content

Commit

Permalink
compiler: fix named string to []byte slice conversion
Browse files Browse the repository at this point in the history
This was missing a `.Underlying()` call to avoid testing the named type
(but instead test for the underlying type).
  • Loading branch information
aykevl authored and deadprogram committed Jul 29, 2020
1 parent e41e510 commit d4e04e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
3 changes: 3 additions & 0 deletions testdata/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d4e04e4

Please sign in to comment.