Skip to content

Commit 446b8b0

Browse files
committed
test: move return-1605 regression test to _demo with validation
Move the regression test for issue #1608/#1604 from cl/_testgo to _demo/go/return-1605 with proper validation logic that panics if the returned slice has wrong length or elements.
1 parent 42218be commit 446b8b0

File tree

4 files changed

+35
-137
lines changed

4 files changed

+35
-137
lines changed

_demo/go/return-1605/main.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
// Regression test for https://github.com/goplus/llgo/issues/1608
4+
5+
type T struct {
6+
data []int
7+
}
8+
9+
func a() []int {
10+
var t = T{data: []int{1, 2}}
11+
a := t.data
12+
t.data = []int{1, 2, 3}
13+
return a
14+
}
15+
16+
func b() ([]int, bool) {
17+
var t = T{data: []int{1, 2}}
18+
a := t.data
19+
t.data = []int{1, 2, 3}
20+
return a, true
21+
}
22+
23+
func main() {
24+
resultA := a()
25+
if len(resultA) != 2 || resultA[0] != 1 || resultA[1] != 2 {
26+
panic("a(): expect [1,2] but got different")
27+
}
28+
29+
resultB, _ := b()
30+
if len(resultB) != 2 || resultB[0] != 1 || resultB[1] != 2 {
31+
panic("b(): expect [1,2] but got different")
32+
}
33+
34+
println("ok")
35+
}

cl/_testgo/return-1605/expect.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

cl/_testgo/return-1605/main.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

cl/_testgo/return-1605/out.ll

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)