aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-03-16 23:48:50 +0100
committerRon Evans <[email protected]>2023-03-18 17:53:47 +0100
commit5b42871baaf19d83b75d4ef298079888c983a54b (patch)
tree3067007e5130670211df44cb3b4115850f2bc110 /testdata
parentc5598630c94e51895e8c7361751512d7bde943aa (diff)
downloadtinygo-5b42871baaf19d83b75d4ef298079888c983a54b.tar.gz
tinygo-5b42871baaf19d83b75d4ef298079888c983a54b.zip
compiler: support all kinds of recursive types
Previously we only supported recursive types in structs. But there can be other kinds of recursive types, like slices: type RecursiveSlice []RecursiveSlice This doesn't involve structs, so it led to infinite recursion in the compiler. This fix avoids recursion at the proper level: at the place where the named type is defined.
Diffstat (limited to 'testdata')
-rw-r--r--testdata/slice.go6
-rw-r--r--testdata/slice.txt1
2 files changed, 7 insertions, 0 deletions
diff --git a/testdata/slice.go b/testdata/slice.go
index 18b80b7c4..fbb1d45cc 100644
--- a/testdata/slice.go
+++ b/testdata/slice.go
@@ -6,6 +6,8 @@ type MySlice [32]byte
type myUint8 uint8
+type RecursiveSlice []RecursiveSlice
+
// Indexing into slice with named type (regression test).
var array = [4]int{
myUint8(2): 3,
@@ -160,6 +162,10 @@ func main() {
for _, c := range named {
assert(c == 0)
}
+
+ // Test recursive slices.
+ rs := []RecursiveSlice(nil)
+ println("len:", len(rs))
}
func printslice(name string, s []int) {
diff --git a/testdata/slice.txt b/testdata/slice.txt
index ea8d4491a..d16a0bda9 100644
--- a/testdata/slice.txt
+++ b/testdata/slice.txt
@@ -16,3 +16,4 @@ bytes: len=6 cap=6 data: 1 2 3 102 111 111
slice to array pointer: 1 -2 20 4
unsafe.Add array: 1 5 8 4
unsafe.Slice array: 3 3 9 15 4
+len: 0