Closed wata727 closed 1 year ago
I think the problem is this: nesting named types is possible: it's allowed by the type signatures and the compiler will let you do it -- but it's not supported: the type checker doesn't know what to do with it.
For example, nesting happens here:
var rangeTy = types.Named("range", types.NewObject(
[]*types.StaticProperty{
types.NewStaticProperty("filename", types.S),
types.NewStaticProperty("start", posTy), # <<<<<< nested named type
types.NewStaticProperty("end", posTy),
},
nil,
)).Description("range of a source file")
var posTy = types.Named("pos", types.NewObject(
[]*types.StaticProperty{
types.NewStaticProperty("line", types.N),
types.NewStaticProperty("column", types.N),
types.NewStaticProperty("byte", types.N),
},
nil,
)).Description("position of a source file")
Named types, as used for generating the builtin function documentation, can only appear on the top level. So, the first argument to a function, or some other argument; and its return value can be named. A property of an object type cannot.
Thank you for your reply. Fair enough.
In that case, it would be nice if types.Named()
had documentation for that.
Short description
I'm building a custom CLI to extend OPA. It offers some custom built-in functions, but I've noticed frequent panics when combining them.
Steps To Reproduce
Panic occurs when you run
go run main.go
with the code below:Expected behavior
It doesn't panic and returns successfully.
Additional context
This error seems to be caused by a condition that is not supposed to be reached: https://github.com/open-policy-agent/opa/blob/v0.48.0/ast/check.go#L828
Unfortunately, I didn't know how to fix it...
Environments: