oracle: Fix find-definition on expressions inside ast.Not nodes (#8731)

`ast.Node.Location` wasn't properly copied during `ResolveRefs` compiler
stage

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
This commit is contained in:
Johan Fylling
2026-06-03 17:09:51 +02:00
committed by GitHub
parent 9e103847d0
commit 2a41f710e1
2 changed files with 84 additions and 0 deletions
+1
View File
@@ -5540,6 +5540,7 @@ func resolveRefsInExpr(globals map[Var]*usedRef, ignore *declaredVarStack, expr
cpy.Terms = &Not{
Body: resolveRefsInBody(globals, ignore, ts.Body),
ExplicitBody: ts.ExplicitBody,
Location: ts.Location,
}
case *LogicalAnd:
cpy.Terms = &LogicalAnd{
+83
View File
@@ -878,6 +878,89 @@ str1 := $"{a} {b}"`,
Text: []byte("b := false"),
},
},
{
note: "negation - legacy",
modules: map[string]string{
"buffer.rego": `package test
p if {
not f(1)
}
f(x) := x`,
},
pos: 26, // position of 'f' inside the negated expression in p
exp: &ast.Location{
File: "buffer.rego",
Row: 7,
Col: 1,
Text: []byte("f(x) := x"),
},
},
{
note: "negation - import, implicit body",
modules: map[string]string{
"buffer.rego": `package test
import future.keywords.not
p if {
not f(1)
}
f(x) := x`,
},
pos: 53, // position of 'f' inside the negated expression in p
exp: &ast.Location{
File: "buffer.rego",
Row: 8,
Col: 1,
Text: []byte("f(x) := x"),
},
},
{
note: "negation - import, explicit body",
modules: map[string]string{
"buffer.rego": `package test
import future.keywords.not
p if {
not {
f(1)
}
}
f(x) := x`,
},
pos: 57, // position of 'f' inside the negated expression in p
exp: &ast.Location{
File: "buffer.rego",
Row: 10,
Col: 1,
Text: []byte("f(x) := x"),
},
},
{
note: "negation - import, explicit body, local var",
modules: map[string]string{
"buffer.rego": `package test
import future.keywords.not
p if {
not {
x := 42
x != 2
}
}`,
},
pos: 67, // position of 'x' inside the negated expression in p
exp: &ast.Location{
File: "buffer.rego",
Row: 6,
Col: 3,
Text: []byte("x"),
},
},
}
for _, tc := range cases {