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

[PHP] missing parentheses in generated output of switch case #6720

Closed
azrafe7 opened this issue Oct 30, 2017 · 6 comments
Closed

[PHP] missing parentheses in generated output of switch case #6720

azrafe7 opened this issue Oct 30, 2017 · 6 comments
Assignees
Labels
platform-php Everything related to PHP

Comments

@azrafe7
Copy link
Contributor

azrafe7 commented Oct 30, 2017

Isolated from a bigger sample, so it's a bit convoluted.

    var x = "test";
    var a:Int = 0;
    var b:Int = 1;
    
    var xor = switch (x) {
      case "test":
        (a != 0) != (b != 0);
      default:
        true;
    }

generates this php code:

  $x = "test";
  $a = 0;
  $b = 1;
  $xor = ($x === "test" ? $a !== 0 !== ($b !== 0) : true);

which results in Parse error: syntax error, unexpected '!==' (T_IS_NOT_IDENTICAL).

@RealyUniqueName
Copy link
Member

Which haxe version?
Do you compile with -D php7?

@RealyUniqueName RealyUniqueName self-assigned this Oct 30, 2017
@RealyUniqueName RealyUniqueName added the platform-php Everything related to PHP label Oct 30, 2017
@azrafe7
Copy link
Contributor Author

azrafe7 commented Oct 30, 2017

haxe 4.0.0 (git build development @ c76e38a)

Yes, compiled -D php7.

@RealyUniqueName
Copy link
Member

@Simn that (a != 0) != (b != 0) comes to generator without the first parens:

[Binop:Bool]
	[Local a(1208):Int]
	!=
	[Const:Int] 0
!=
[Parenthesis:Bool]
	[Binop:Bool]
		[Local b(1209):Int]
		!=
		[Const:Int] 0

Is it a bug in analyzer?

@Simn
Copy link
Member

Simn commented Oct 30, 2017

Try adding @:analyzer(full_debug) to the function and check stdout. It tells you how the expression arrives at the analyzer (in <initial>), so we can tell if it's an analyzer problem or comes from another part of the compiler.

@RealyUniqueName
Copy link
Member

Oh, i guess it's fine for normal languages to have expressions like a != b != c because all binops have the same prescedence. Looks perfectly valid. But not for PHP interpreter.

@azrafe7
Copy link
Contributor Author

azrafe7 commented Oct 30, 2017

That was fast... thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-php Everything related to PHP
Projects
None yet
Development

No branches or pull requests

3 participants