diff options
author | Ayke van Laethem <[email protected]> | 2019-09-26 15:36:23 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-10-01 21:31:00 +0200 |
commit | 01e58691a16a9bea24b6ea5e57b81c95133af86a (patch) | |
tree | ba11c829d4592262914b23d4f60a63b6f8f45956 | |
parent | 81c0f9af4e30485726f15b2342244b39a042ac96 (diff) | |
download | tinygo-01e58691a16a9bea24b6ea5e57b81c95133af86a.tar.gz tinygo-01e58691a16a9bea24b6ea5e57b81c95133af86a.zip |
compiler: support constant indices with a named type
-rw-r--r-- | compiler/asserts.go | 2 | ||||
-rw-r--r-- | testdata/slice.go | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/compiler/asserts.go b/compiler/asserts.go index b9f02e849..ad79c0a13 100644 --- a/compiler/asserts.go +++ b/compiler/asserts.go @@ -22,7 +22,7 @@ func (c *Compiler) emitLookupBoundsCheck(frame *Frame, arrayLen, index llvm.Valu if index.Type().IntTypeWidth() < arrayLen.Type().IntTypeWidth() { // Sometimes, the index can be e.g. an uint8 or int8, and we have to // correctly extend that type. - if indexType.(*types.Basic).Info()&types.IsUnsigned == 0 { + if indexType.Underlying().(*types.Basic).Info()&types.IsUnsigned == 0 { index = c.builder.CreateZExt(index, arrayLen.Type(), "") } else { index = c.builder.CreateSExt(index, arrayLen.Type(), "") diff --git a/testdata/slice.go b/testdata/slice.go index 8182af36d..d20de76d3 100644 --- a/testdata/slice.go +++ b/testdata/slice.go @@ -2,6 +2,13 @@ package main type MySlice [32]byte +type myUint8 uint8 + +// Indexing into slice with named type (regression test). +var array = [4]int{ + myUint8(2): 3, +} + func main() { l := 5 foo := []int{1, 2, 4, 5} |