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

If / Float / Bool problem #19

Open
Lemage74 opened this issue Mar 24, 2013 · 1 comment
Open

If / Float / Bool problem #19

Lemage74 opened this issue Mar 24, 2013 · 1 comment

Comments

@Lemage74
Copy link

Hi,

I noticed a Float/Bool conversion problem while trying to test an expression such as:
if ( xxx > 0.5) doSomething;
xxx being a Float

Compiler gives: "Float should be Bool" for the expression "xxx > 0.5"

The problem is that comparison operations between Float return a Float which value is 0 or 1 but if test requires a Bool and there is no conversion.

It seems to occurs in Compiler.hx when on line 206 is called "unify(cond.t, TBool, e.p);"
unify calls tryUnify which throws that error.

I also noticed that expressions such as if (aConstant == null) or if (aConstant!=null) do compile as they seem to return a Bool.

I presume that that exception is linked with the lines 801-817 of Compiler.hx, in the makeOp method.
That block starts with the comment: // if we have a null check, infer a VParam

On line 76, I tried to replace:
case CMin, CMax, CLt, CGte, CEq, CNeq, CLte, CGt: floats;
By:
case CMin, CMax: floats;
case CLt, CGte, CEq, CNeq, CLte, CGt: [ { p1 : TFloat4, p2 : TFloat4, r : TFloat4}, { p1 : TFloat3, p2 : TFloat3, r : TFloat3}, { p1 : TFloat2, p2 : TFloat2, r : TFloat2} , { p1 : TFloat, p2 : TFloat, r : TBool } ];
My shader compiled but failed at runtime.

I also tried to put in tryUnify, after the line 740:
case TFloat: return (t2 == TFloat || t2 == TBool);
but I had the same result. It compiled but failed at runtime.

Thank you for your work,
Olivier.

@ncannasse
Copy link
Owner

yes, such compile-time comparisons are not yet supported because we currently only track changes in Bools as a bit-flag

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

2 participants