csyonghe / Spire

Other
174 stars 22 forks source link

Type-checking issue for ternary (`?:`) operator #29

Closed tangent-vector closed 8 years ago

tangent-vector commented 8 years ago

This code:

float a, b, c;
a = true ? b : c;

Yields the error message:

error 30080: the two value expressions in a select clause must evaluate to same type.
csyonghe commented 8 years ago

This is fixed in latest code but I can't push now, to fix in your branch, search "Error(30080, L"the two value" and modify the if statement above it to:

if (!expr->Expr0->Type->Equals(expr->Expr1->Type))

tangent-vector commented 8 years ago

I worked around this for now by using an if statement. If I find that I need the fix I will apply it. Thanks!

tangent-vector commented 8 years ago

Tried applying that fix, and it seems to fail on implicit conversion of the expr->Expr1->Type part to an ordinary pointer (it is a smart pointer). I inserted an explicit call to .Ptr() and it was fine, so I'm not sure what is the reason for the issue.

Also note that I appear to have run into a suspiciously similar issue with Spire's range-style for loop where I get an error 30019: type mismatch 'int' and 'int'. Looking at the code of VisitForStatement there appear to be similar type != tests that need to be changed to use Equals.

csyonghe commented 8 years ago

That's a good catch. Yes, '==' must be replaced with ->Equals in all these places. And yes, .Ptr() should be added. Thanks!

csyonghe commented 8 years ago

this issue is fixed in latest update.