lep / pjass

The famous jass syntax checker.
BSD 2-Clause "Simplified" License
25 stars 6 forks source link

Precedence of comparing operations #10

Closed Prometheus3375 closed 6 months ago

Prometheus3375 commented 6 months ago
function foo takes nothing returns nothing
    local boolean b = 5 > 4 == 5 < 7
endfunction

This code produces error: image

Actually, at first < and > are evaluated and then ==.


function foo takes nothing returns nothing
    local boolean a = 1 != 2 != false
endfunction

Error: image

This once correctly evaluates to true.

There can be other issues related to precedence in comparisons.

lep commented 6 months ago

Surprising. I think i checked this once (long ago). So either i failed or they actually touched the parsing part in recent patches. Thanks for the report. Should be fixed with dec9c9c523f4793746557d92f6ab9429ffa2ff21

Prometheus3375 commented 6 months ago

I've just checked in 1.26, map was working OK.

According to the description I found, precedence goes in the following way (from highest to lowest):

I am not sure about comparison operations and modulo.

UPD: I checked a bit looks like this list is legit.

Prometheus3375 commented 6 months ago

Well, actually...

if false and true or true then
    call BJDebugMsg("true")
else 
    call BJDebugMsg("false")
endif

In this case the whole expression is evaluated to false. 🤣 This is because of and optimization, or is never evaluated.