wc3edit.net https://forum.wc3edit.net/ |
|
This function compiles http://forum.wc3edit.net/deprotection-cheating-f64/this-function-compiles-t37294.html |
Page 1 of 1 |
Author: | owner123 [ April 14th, 2020, 8:57 pm ] |
Post subject: | This function compiles |
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:
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. |
Author: | nuzamacuxe [ April 15th, 2020, 12:31 am ] |
Post subject: | Re: This function compiles |
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. |
Author: | owner123 [ April 15th, 2020, 1:34 am ] |
Post subject: | Re: This function compiles |
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. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |