diff options
author | Ayke van Laethem <[email protected]> | 2020-07-27 12:35:29 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-07-29 12:13:37 +0200 |
commit | d4e04e4e493aa4a99659361e28b22ecd51cceee3 (patch) | |
tree | 484d986b73f6e75a38732527816f8f310bd09a72 | |
parent | e41e5106cca28d9ccfb976dc38562ab08388c09f (diff) | |
download | tinygo-d4e04e4e493aa4a99659361e28b22ecd51cceee3.tar.gz tinygo-d4e04e4e493aa4a99659361e28b22ecd51cceee3.zip |
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).
-rw-r--r-- | compiler/compiler.go | 2 | ||||
-rw-r--r-- | testdata/string.go | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/compiler/compiler.go b/compiler/compiler.go index fe45eb3fc..7b52cb66b 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -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") } diff --git a/testdata/string.go b/testdata/string.go index 1c5ce6300..7eb90173c 100644 --- a/testdata/string.go +++ b/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 } |