compiler: support constant indices with a named type
Этот коммит содержится в:
родитель
81c0f9af4e
коммит
01e58691a1
2 изменённых файлов: 8 добавлений и 1 удалений
|
@ -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(), "")
|
||||
|
|
7
testdata/slice.go
предоставленный
7
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}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче