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 Check fail #7

Open
LKlinke opened this issue Jul 13, 2022 · 2 comments
Open

Type Check fail #7

LKlinke opened this issue Jul 13, 2022 · 2 comments

Comments

@LKlinke
Copy link
Collaborator

LKlinke commented Jul 13, 2022

from probably.pgcl.compiler import compile_pgcl

compile_pgcl("""
nat s;
nat c;
nat tmp;
tmp :=((1-(1-(c*c))^(1/2))/c)
""")

Results in

CheckFail(location=BinopExpr(operator=Binop.POWER,
lhs=BinopExpr(operator=Binop.MINUS,
        lhs=NatLitExpr(1),
        rhs=BinopExpr(operator=Binop.TIMES, lhs=VarExpr('c'), rhs=VarExpr('c'))
    ),
rhs=RealLitExpr("1/2")),
message='Expected value of type NatType(bounds=None), got RealType().')
@Philipp15b
Copy link
Owner

What's the minimal program/expression that triggers this?

@Legotier
Copy link
Collaborator

Legotier commented Jul 28, 2022

This is triggered by the expression ((1-(1-(c*c))^(1/2))/c). It happens because the function is_compatible() in check.py doesn't behave as documented; NatTypes are not compatible with RealTypes, i.e., n^(1/2) is wrongly typed if n is a natural number.

A simple fix would be to change line 309 in check.py from if isinstance(lhs, NatType) and isinstance(rhs, NatType): to if isinstance(lhs, NatType) and isinstance(rhs, (NatType, RealType)):, though this seems to break one of the testcases.

(it might be possible that I'm misunderstanding the concept of compatibility here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants