compile: Allow object generating rules to be annotated as entrypoint (#5578)

Using ground ref of rule when generating entrypoint from annotation
as variable in head suffix cannot be included in generated entrypoint path.

Fixes: #5577
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
This commit is contained in:
Johan Fylling
2023-01-23 21:47:24 +01:00
committed by GitHub
parent 45e3a62e23
commit 9f7e5e6be6
2 changed files with 95 additions and 1 deletions
+94
View File
@@ -477,6 +477,100 @@ package test
p[1]
f(x) { p[x] }
`,
},
err: nil,
},
{
note: "set generation with annotated entrypoint",
files: map[string]string{
"test.rego": `
package test
# METADATA
# entrypoint: true
p[x] {
{"a", "b"}[x]
}
`,
},
err: nil,
},
{
note: "set generation with annotated entrypoint (contains if)",
files: map[string]string{
"test.rego": `
package test
import future.keywords
# METADATA
# entrypoint: true
p contains x if {
{"a", "b"}[x]
}
`,
},
err: nil,
},
{
note: "object generation with annotated entrypoint",
files: map[string]string{
"test.rego": `
package test
# METADATA
# entrypoint: true
p[i] := x {
x := ["a", "b"][i]
}
`,
},
err: nil,
},
{
note: "object generation with annotated entrypoint (if)",
files: map[string]string{
"test.rego": `
package test
import future.keywords
# METADATA
# entrypoint: true
p[i] if {
{"a", "b"}[i]
}
`,
},
err: nil,
},
{
note: "dots in head with annotated entrypoint",
files: map[string]string{
"test.rego": `
package test
# METADATA
# entrypoint: true
p.a.b if {
true
}
`,
},
err: nil,
},
{
note: "dots in head object generation with annotated entrypoint",
files: map[string]string{
"test.rego": `
package test
# METADATA
# entrypoint: true
p.a.b[i] := x {
x := ["a", "b"][i]
}
`,
},
err: nil,
+1 -1
View File
@@ -234,7 +234,7 @@ func addEntrypointsFromAnnotations(c *Compiler, ar []*ast.AnnotationsRef) error
}
case "rule":
if r := ref.GetRule(); r != nil {
entrypoint = r.Ref()
entrypoint = r.Ref().GroundPrefix()
}
default:
continue // Wrong scope type. Bail out early.