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:
@@ -588,6 +588,32 @@ func TestInterpretMany(t *testing.T) {
|
||||
graph: graph,
|
||||
})
|
||||
}
|
||||
{
|
||||
graph, _ := pgraph.NewGraph("g")
|
||||
r1, _ := engine.NewNamedResource("test", "hey1")
|
||||
r2, _ := engine.NewNamedResource("test", "hey2")
|
||||
x1 := r1.(*resources.TestRes)
|
||||
x2 := r2.(*resources.TestRes)
|
||||
s1, s2 := "hey", "hey"
|
||||
x1.StringPtr = &s1
|
||||
x2.StringPtr = &s2
|
||||
graph.AddVertex(x1, x2)
|
||||
testCases = append(testCases, test{
|
||||
name: "double include with out of order variable in parent scope and scoped var",
|
||||
code: `
|
||||
include c1($foo + "1")
|
||||
include c1($foo + "2")
|
||||
class c1($a) {
|
||||
test $a {
|
||||
stringptr => $foo,
|
||||
}
|
||||
}
|
||||
$foo = "hey"
|
||||
`,
|
||||
fail: false,
|
||||
graph: graph,
|
||||
})
|
||||
}
|
||||
{
|
||||
graph, _ := pgraph.NewGraph("g")
|
||||
r1, _ := engine.NewNamedResource("test", "t1")
|
||||
|
||||
Reference in New Issue
Block a user