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

Type checker returning spurious undefined function errors #2155

Closed
tsandall opened this issue Feb 27, 2020 · 0 comments · Fixed by #2231
Closed

Type checker returning spurious undefined function errors #2155

tsandall opened this issue Feb 27, 2020 · 0 comments · Fixed by #2231
Assignees
Labels

Comments

@tsandall
Copy link
Member

tsandall commented Feb 27, 2020

The type checker requires that the caller sort the rules topologically however for independent rules (p and q below) there is no ordering requirement (and the ordering for independent rules is currently non-deterministic.) This results in spurious undefined function errors. For example:

package x

p { 
  concat("", 1)  # type error
}

q {
  f(1)
}

f(x) = x

The spurious "undefined function" errors are emitted because the type checker does not update the type environment once it finds a single error AND the order that independent rules are checked in is non-deterministic. For example:

case 1:

f  # no error, f added to type env
q  # no error, q added to type env
p  # concat type error, p not added to type env

case 2:

p  # concat type error, p not added to type env
f  # no error, but since checker contains error for p, f not added to type env
q  # undefined function error since f not in type env

This is related to #2091 but not quite the same. It's possible that the solution for this issue could resolve #2091. For example, the type checker could be updated to add rules/functions to the type env EVEN IF they contain errors. Since the types of terms in the head of the rule can't be inferred reliably in this case, they could be added as ANY types. This would mean dependents of erroneous rules/functions would not encounter "undefined function" or "undefined ref" or other type errors. This would be nice because independent rules could still be type checked and we can report the maximum number of errors in one pass.

@tsandall tsandall added the bug label Feb 27, 2020
ashutosh-narkar added a commit to ashutosh-narkar/opa that referenced this issue Mar 27, 2020
Earlier if a rule/function contained an error, the type checker would not update the env with subsequent independent rules resulting in errors such as "undefined functions". This change add erroneous rules/functions to the env to avoid such type errors.

Fixes open-policy-agent#2155

Fixes open-policy-agent#2091

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
@ashutosh-narkar ashutosh-narkar self-assigned this Mar 27, 2020
ashutosh-narkar added a commit that referenced this issue Mar 30, 2020
Earlier if a rule/function contained an error, the type checker would not update the env with subsequent independent rules resulting in errors such as "undefined functions". This change add erroneous rules/functions to the env to avoid such type errors.

Fixes #2155

Fixes #2091

Signed-off-by: Ashutosh Narkar <anarkar4387@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