lang: Add partial recursive support/detection to class

This adds the additional bits onto the class/include statements to
support or detect class recursion. It's not currently supported, but
I figured I'd commit the detection code as a variant of the recursion
implementation, since I think this is correct, and it was a bit tricky
for me to get it right.
This commit is contained in:
James Shubin
2018-06-17 17:14:45 -04:00
parent c62b8a5d4f
commit 05f6ba7297
3 changed files with 101 additions and 2 deletions

View File

@@ -800,6 +800,55 @@ func TestInterpretMany(t *testing.T) {
// graph: graph,
// })
//}
// TODO: remove this test if we ever support recursive classes
{
values = append(values, test{
name: "recursive classes fail 1",
code: `
$max = 3
include c1(0) # start at zero
class c1($count) {
if $count == $max {
test "done" {
stringptr => printf("count is %d", $count),
}
} else {
include c1($count + 1) # recursion not supported atm
}
}
`,
fail: true,
})
}
// TODO: remove this test if we ever support recursive classes
{
values = append(values, test{
name: "recursive classes fail 2",
code: `
$max = 5
include c1(0) # start at zero
class c1($count) {
if $count == $max {
test "done" {
stringptr => printf("count is %d", $count),
}
} else {
include c2($count + 1) # recursion not supported atm
}
}
class c2($count) {
if $count == $max {
test "done" {
stringptr => printf("count is %d", $count),
}
} else {
include c1($count + 1) # recursion not supported atm
}
}
`,
fail: true,
})
}
for index, test := range values { // run all the tests
name, code, fail, exp := test.name, test.code, test.fail, test.graph