aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2020-07-27 12:35:29 +0200
committerRon Evans <[email protected]>2020-07-29 12:13:37 +0200
commitd4e04e4e493aa4a99659361e28b22ecd51cceee3 (patch)
tree484d986b73f6e75a38732527816f8f310bd09a72
parente41e5106cca28d9ccfb976dc38562ab08388c09f (diff)
downloadtinygo-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.go2
-rw-r--r--testdata/string.go3
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
}