Skip to content

Commit 2ce91e1

Browse files
committed
fix slice array compute new length
1 parent 70d1b58 commit 2ce91e1

File tree

3 files changed

+244
-257
lines changed

3 files changed

+244
-257
lines changed

compiler/compiler/slice.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,13 @@ func (c *Compiler) compileSliceArray(src value.Value, v *parser.SliceArrayNode,
125125
endIndexValue.Value = constant.NewInt(llvmTypes.I32, int64(arrTy.Len))
126126
}
127127
}
128-
129128
endIndex := internal.LoadIfVariable(c.contextBlock, endIndexValue)
129+
if startIndex.Type() != llvmTypes.I64 {
130+
startIndex = c.contextBlock.NewZExt(startIndex, i64.LLVM())
131+
}
132+
if endIndex.Type() != llvmTypes.I64 {
133+
endIndex = c.contextBlock.NewZExt(endIndex, i64.LLVM())
134+
}
130135
sliceLen := c.contextBlock.NewSub(endIndex, startIndex)
131136
var sliceLen32 llvmValue.Value
132137
sliceLen32 = sliceLen

0 commit comments

Comments
 (0)