This function compiles

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

Post Reply
owner123
Super Moderator
Posts: 1943
Joined: February 3rd, 2009, 11:28 pm

This function compiles

Post by owner123 »

Alright JASS coders, I have an interesting little puzzle here.

This is a function that exists in DotA Allstars v6.83d-fixed. You can extract the .j and then find this function

Code: Select all

function Trig_Spawn_Conditions takes nothing returns boolean
return true
if(INI)then
return ISI
endif
if(IQI)then
return IUI
endif
if(E2)then
return D2
endif
if QT0 then
return QR0
endif
if(N2)then
return I3
endif
if(K0)then
return PG0
endif
if(IAI)then
return IBI
endif
if(CN)then
return PW0
endif
return O0
endfunction

Now, this function has a return at the top and then more code below it (which is obviously unreachable) and another return statement at the bottom. It should be functionally equivalent to "return true". Any ideas on why code like this would ever be written? Maybe just to troll people like me?

This sort of JASS compilation trick was supposed to be patched year ago when the return bug was fixed.

Do you guys have any theories on why this compiles?

Mine:
Spoiler:
This function is never called, so the JASS compiler doesn't apply the same level of logical verification that it does elsewhere. The code in between the two top-level returns is enough to fool the compiler into allowing it.


Bonus

DotA Allstars also defines the following global variable:

Code: Select all

integer array DD0

Later on in function VJ1, it defines the following local:

Code: Select all

local string DD0


Why do these variables not collide?
Does JASS actually allow this if they are different datatypes? I feel like it doesn't, and it shouldn't.
This function does get called. So my theory above doesn't apply.
Maybe it allows it if one is an array and one isn't, since compiler confusing is impossible there.
User avatar
nuzamacuxe
Also Not an Admin, but closer than devoltz
Posts: 1655
Joined: February 14th, 2018, 5:35 am
Title: Just Another S.Mod

Re: This function compiles

Post by nuzamacuxe »

It's not related to not being called. If there's a function wrote there, it'll be compiled. Seems like you can do multiple returns since you return the correct datatype. About the collide thing, it's not related to datatypes. You can do a local integer A and a global integer A that it wont interfer anything.
owner123
Super Moderator
Posts: 1943
Joined: February 3rd, 2009, 11:28 pm

Re: This function compiles

Post by owner123 »

Interesting - I tested and you're correct. It does allow multiple return values all the time

Code: Select all

function test takes nothing returns boolean
    return true
    return false
endfunction

None of the other languages I code would allow you to do this. I guess it's just another way that JASS is poorly made.

And I guess if you declare a local with the same name as a global, then you just can't modify the global in that method. You can't exactly do "this.variable" in JASS.
I guess that makes sense.
Post Reply