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

Function arguments do not shadow built-in function namespace #2080

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

Function arguments do not shadow built-in function namespace #2080

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

Comments

@tsandall
Copy link
Member

tsandall commented Feb 9, 2020

Variables declared as function arguments should shadow built-in functions. For example:

> f(object) { object[_] == 1 }
1 error occurred: 1:13: rego_type_error: match error
	left  : ???
	right : number

In this case the type checker generates a match error because it thinks object[_] refers to the built-in function namespace that includes the new object.get function. This issue is not specific to the new object namespace, e.g., the same issue happens w/ other built-in functions:

> f(http) { http[_] == 1 }
1 error occurred: 1:11: rego_type_error: match error
	left  : ???
	right : number

The problem is that vars declared in function argument lists are not being rewritten.

@tsandall tsandall added the bug label Feb 9, 2020
@tsandall tsandall self-assigned this Feb 9, 2020
tsandall added a commit to tsandall/opa that referenced this issue Feb 9, 2020
Vars declared as rule args were not being rewritten which lead to
namespace conflicts with built-in functions. For example, definitions
like `f(object) { object[x] = 1 }` would generate type checking errors
because the checker would treat `object[x] = 1` as referring to the
`object` built-in function namespace.

This change updates the compiler to rewrite rule arguments just like
it does other declared variables.

Fixes open-policy-agent#2080

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Feb 9, 2020
Vars declared as rule args were not being rewritten which lead to
namespace conflicts with built-in functions. For example, definitions
like `f(object) { object[x] = 1 }` would generate type checking errors
because the checker would treat `object[x] = 1` as referring to the
`object` built-in function namespace.

This change updates the compiler to rewrite rule arguments just like
it does other declared variables.

Fixes #2080

Signed-off-by: Torin Sandall <torinsandall@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.

1 participant