lang: Fix import scoping issue with classes
When include-ing a class, we propagated the scope of the include into the class instead of using the correct scope that existed when the class was defined and instead propagating only the include arguments in. This patch fixes the issue and adds a ton of tests as well. It also propagates the scope into the include args, in case that is needed, and adds a test for that as well. Thanks to Nicolas Charles for the initial bug report.
This commit is contained in:
24
lang/interpret_test/TestAstFunc1/recursive_class2/main.mcl
Normal file
24
lang/interpret_test/TestAstFunc1/recursive_class2/main.mcl
Normal file
@@ -0,0 +1,24 @@
|
||||
# this currently fails with: "class `c1` does not exist in this scope"
|
||||
# instead of: "recursive class `c1` found" or "recursive class `c2` found"
|
||||
# ideally, we'd consider allowing finite (static) recursion such as this...
|
||||
import "fmt"
|
||||
$max = 5
|
||||
include c1(0) # start at zero
|
||||
class c1($count) {
|
||||
if $count == $max {
|
||||
test "done" {
|
||||
stringptr => fmt.printf("count is %d", $count),
|
||||
}
|
||||
} else {
|
||||
include c2($count + 1) # recursion not supported atm
|
||||
}
|
||||
}
|
||||
class c2($count) {
|
||||
if $count == $max {
|
||||
test "done" {
|
||||
stringptr => fmt.printf("count is %d", $count),
|
||||
}
|
||||
} else {
|
||||
include c1($count + 1) # recursion not supported atm
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user