Skip to content

Commit fea56d4

Browse files
aykevldeadprogram
authored andcommitted
compiler: add support for full slice expression for slicing arrays
This was an oversight in the main commit for full slice expressions: #472 This syntax is used by the regexp package, for example.
1 parent ea8e407 commit fea56d4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

compiler/compiler.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,9 +1776,6 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) {
17761776

17771777
switch typ := expr.X.Type().Underlying().(type) {
17781778
case *types.Pointer: // pointer to array
1779-
if expr.Max != nil {
1780-
return llvm.Value{}, c.makeError(expr.Pos(), "todo: full slice expressions (with max): "+expr.Type().String())
1781-
}
17821779
// slice an array
17831780
length := typ.Elem().Underlying().(*types.Array).Len()
17841781
llvmLen := llvm.ConstInt(c.uintptrType, uint64(length), false)

testdata/slice.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ func main() {
7979
assert(cap(longfoo[uint64(1):uint64(3):uint64(5)]) == 4)
8080
assert(cap(longfoo[uintptr(1):uintptr(3):uintptr(5)]) == 4)
8181

82+
// slicing an array with max parameter (added in Go 1.2)
83+
assert(cap(arr[int(1):int(2):int(4)]) == 3)
84+
assert(cap(arr[int8(1):int8(2):int8(4)]) == 3)
85+
assert(cap(arr[int16(1):int16(2):int16(4)]) == 3)
86+
assert(cap(arr[int32(1):int32(2):int32(4)]) == 3)
87+
assert(cap(arr[int64(1):int64(2):int64(4)]) == 3)
88+
assert(cap(arr[uint(1):uint(2):uint(4)]) == 3)
89+
assert(cap(arr[uint8(1):uint8(2):uint8(4)]) == 3)
90+
assert(cap(arr[uint16(1):uint16(2):uint16(4)]) == 3)
91+
assert(cap(arr[uint32(1):uint32(2):uint32(4)]) == 3)
92+
assert(cap(arr[uint64(1):uint64(2):uint64(4)]) == 3)
93+
assert(cap(arr[uintptr(1):uintptr(2):uintptr(4)]) == 3)
94+
8295
// copy
8396
println("copy foo -> bar:", copy(bar, foo))
8497
printslice("bar", bar)

0 commit comments

Comments
 (0)