wc3edit.net

United Warcraft 3 map hacking!
It is currently May 25th, 2020, 1:52 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: This function compiles
PostPosted: April 14th, 2020, 8:57 pm 
Offline
Super Moderator

Joined: February 3rd, 2009, 11:28 pm
Posts: 2329
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:
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:
integer array DD0

Later on in function VJ1, it defines the following local:
Code:
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.


Top
 Profile  
 
PostPosted: April 15th, 2020, 12:31 am 
Offline
Also Not an Admin, but closer than devoltz
User avatar

Joined: February 14th, 2018, 5:35 am
Posts: 1379
Title: Just Another S.Mod
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.


Top
 Profile  
 
PostPosted: April 15th, 2020, 1:34 am 
Offline
Super Moderator

Joined: February 3rd, 2009, 11:28 pm
Posts: 2329
Interesting - I tested and you're correct. It does allow multiple return values all the time
Code:
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

phpBB SEO


Privacy Policy Statement
Impressum (German)