Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: Functions defined with calls in the argument list #2081

Closed
tsandall opened this issue Feb 9, 2020 · 0 comments · Fixed by #2185
Closed

panic: Functions defined with calls in the argument list #2081

tsandall opened this issue Feb 9, 2020 · 0 comments · Fixed by #2185
Assignees
Labels

Comments

@tsandall
Copy link
Member

tsandall commented Feb 9, 2020

If a function is defined with a call in the argument list, the compiler panics. The compiler should be rewriting these args like it does with other terms that require evaluation (e.g., refs, comprehensions, etc.)

> g(x) = x
1 error occurred: 1:1: rego_type_error: undefined function g
> f(g(1)) { true }
panic: unreachable [recovered]
	panic: unreachable

goroutine 1 [running]:
github.com/open-policy-agent/opa/ast.(*Compiler).compile.func1()
	/src/ast/compile.go:846 +0x73
panic(0xe7f740, 0x1099990)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/open-policy-agent/opa/ast.(*TypeEnv).Get(0xc0002d2160, 0xf59fa0, 0xc0002d0de0, 0x0, 0x0)
	/src/ast/env.go:133 +0xff7
github.com/open-policy-agent/opa/ast.getArgTypes(0xc0002d2160, 0xc0002d0aa8, 0x2, 0x2, 0x0, 0x0, 0xfa5be9)
	/src/ast/check.go:980 +0x8b
github.com/open-policy-agent/opa/ast.(*typeChecker).checkExprEq(0xc0002d46c0, 0xc0002d2160, 0xc00018de00, 0x2)
	/src/ast/check.go:278 +0xa3
github.com/open-policy-agent/opa/ast.(*typeChecker).checkExpr(0xc0002d46c0, 0xc0002d2160, 0xc00018de00, 0x0)
	/src/ast/check.go:218 +0xc8
github.com/open-policy-agent/opa/ast.(*typeChecker).CheckBody.func1(0xc00018de00, 0x1)
	/src/ast/check.go:74 +0x34e
github.com/open-policy-agent/opa/ast.WalkExprs.func1(0xf7ca80, 0xc00018de00, 0x1)
	/src/ast/visit.go:205 +0x42
github.com/open-policy-agent/opa/ast.(*GenericVisitor).Walk(0xc000226f98, 0xf7ca80, 0xc00018de00)
	/src/ast/visit.go:270 +0x5b
github.com/open-policy-agent/opa/ast.(*GenericVisitor).Walk(0xc000226f98, 0xf5b620, 0xc0002d1120)
	/src/ast/visit.go:308 +0xb16
github.com/open-policy-agent/opa/ast.WalkExprs(0xf5b620, 0xc0002d1120, 0xc000227008)
	/src/ast/visit.go:209 +0x70
github.com/open-policy-agent/opa/ast.(*typeChecker).CheckBody(0xc0002d46c0, 0xc0002d2160, 0xc0002d2100, 0x2, 0x2, 0x203000, 0x203000, 0x203000, 0x203000)
	/src/ast/check.go:57 +0x188
github.com/open-policy-agent/opa/ast.(*typeChecker).checkRule(0xc0002d46c0, 0xc0002d2150, 0xc000293a40)
	/src/ast/check.go:149 +0x73
github.com/open-policy-agent/opa/ast.(*typeChecker).CheckTypes(0xc0002d46c0, 0xc0002d2150, 0xc0002d2120, 0x1, 0x1, 0x0, 0x0, 0x0, 0x6000103)
	/src/ast/check.go:101 +0x16a
github.com/open-policy-agent/opa/ast.(*Compiler).checkTypes(0xc0002c48f0)
	/src/ast/compile.go:811 +0x118
github.com/open-policy-agent/opa/ast.(*Compiler).runStage(0xc0002c48f0, 0xfb65eb, 0x19, 0xc0002c1ea0)
	/src/ast/compile.go:832 +0x43
github.com/open-policy-agent/opa/ast.(*Compiler).compile(0xc0002c48f0)
	/src/ast/compile.go:851 +0x115
github.com/open-policy-agent/opa/ast.(*Compiler).Compile(0xc0002c48f0, 0xc0002c6750)
	/src/ast/compile.go:345 +0x2a4
github.com/open-policy-agent/opa/repl.(*REPL).compileRule(0xc00022afc0, 0x10c1720, 0xc00009e018, 0xc000293740, 0x0, 0x0)
	/src/repl/repl.go:665 +0x381
github.com/open-policy-agent/opa/repl.(*REPL).evalStatement(0xc00022afc0, 0x10c1720, 0xc00009e018, 0xf41460, 0xc000293740, 0x1, 0x1)
	/src/repl/repl.go:826 +0xe1
github.com/open-policy-agent/opa/repl.(*REPL).evalBufferOne(0xc00022afc0, 0x10c1720, 0xc00009e018, 0x0, 0x1)
	/src/repl/repl.go:711 +0x2bf
github.com/open-policy-agent/opa/repl.(*REPL).OneShot(0xc00022afc0, 0x10c1720, 0xc00009e018, 0xc000186a00, 0x10, 0x0, 0x0)
	/src/repl/repl.go:253 +0x365
github.com/open-policy-agent/opa/repl.(*REPL).Loop(0xc00022afc0, 0x10c1720, 0xc00009e018)
	/src/repl/repl.go:152 +0x31b
github.com/open-policy-agent/opa/runtime.(*Runtime).StartREPL(0xc0001a6b00, 0x10c1720, 0xc00009e018)
	/src/runtime/runtime.go:375 +0x3c0
github.com/open-policy-agent/opa/cmd.init.7.func1(0xc00019c780, 0x16373f0, 0x0, 0x0)
	/src/cmd/run.go:138 +0x4e4
github.com/spf13/cobra.(*Command).execute(0xc00019c780, 0x16373f0, 0x0, 0x0, 0xc00019c780, 0x16373f0)
	/src/vendor/github.com/spf13/cobra/command.go:766 +0x2ae
github.com/spf13/cobra.(*Command).ExecuteC(0x15d7c60, 0x15d7c60, 0xc0000d1f88, 0x734d9f)
	/src/vendor/github.com/spf13/cobra/command.go:852 +0x2ec
github.com/spf13/cobra.(*Command).Execute(...)
	/src/vendor/github.com/spf13/cobra/command.go:800
main.main()
	/src/main.go:15 +0x32
@tsandall tsandall added the bug label Feb 9, 2020
@patrick-east patrick-east self-assigned this Mar 12, 2020
patrick-east added a commit to patrick-east/opa that referenced this issue Mar 27, 2020
Rather than causing a panic calls in function declaration args will
now just raise a parse error.

In the future we could potentially support them but we would need to
sort out some additional details/ambiguity around behavior.

Its unclear that any users need this behavior so for now we'll just
correct the panic.

Fixes: open-policy-agent#2081
Signed-off-by: Patrick East <east.patrick@gmail.com>
tsandall pushed a commit that referenced this issue Apr 2, 2020
Rather than causing a panic calls in function declaration args will
now just raise a parse error.

In the future we could potentially support them but we would need to
sort out some additional details/ambiguity around behavior.

Its unclear that any users need this behavior so for now we'll just
correct the panic.

Fixes: #2081
Signed-off-by: Patrick East <east.patrick@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants