Nekit1234007 / cjass

Automatically exported from code.google.com/p/cjass
0 stars 0 forks source link

Static if bug #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Try it with UnitIndexer/UnitEvent/Bonus

http://www.hiveworkshop.com/forums/jass-functions-413/system-unit-indexer-172090
/
http://www.hiveworkshop.com/forums/jass-functions-413/extension-unit-event-17236
5/
http://www.hiveworkshop.com/forums/submissions-414/system-bonus-196954/

Don't know what precisely bugs since I encountered the error in a massive map.

Original issue reported on code.google.com by mrasolo...@gmail.com on 12 Aug 2011 at 4:23

GoogleCodeExporter commented 9 years ago
Ok.. update

This is what was crashing AdicParser I think

static if (DEBUG_MODE) then
else
endif

The above parses to

function if takes false returns static
else
endif

when it should parse to nothing

Original comment by mrasolo...@gmail.com on 12 Aug 2011 at 4:36

GoogleCodeExporter commented 9 years ago
Ok, solved another portion of the static if bug.

In UnitIndexer, there are these 2 methods-
        private static method onEnter takes nothing returns boolean
            //retrieve unit and unit type id
            local unit Q = GetFilterUnit()
            local integer i
            local integer d = o
            if (enabled and e[GetUnitUserData(Q)] != Q) then
                if (y == 0) then
                    set r = r + 1
                    set i = r
                else
                    set i = y
                    set y = n[y]
                endif

                call UnitAddAbility(Q, ABILITIES_UNIT_INDEXER)
                call UnitMakeAbilityPermanent(Q, true, ABILITIES_UNIT_INDEXER)
                call SetUnitUserData(Q, i)

                set e[i] = Q

                static if not LIBRARY_UnitList then
                    if (not a)then
                        set p[i] = p[0]
                        set n[p[0]] = i
                        set n[i] = 0
                        set p[0] = i
                    endif
                else
                    set p[i] = p[0]
                    set n[p[0]] = i
                    set n[i] = 0
                    set p[0] = i
                    call GroupAddUnit(g, e[i])
                endif

                set o = i
                call FireEvent(INDEX)
                set o = d
            endif

            set Q = null

            return false
        endmethod

        private static method onLeave takes nothing returns boolean
            static if LIBRARY_UnitEvent then
                implement optional UnitEventModule
            else
                local unit u = GetFilterUnit()
                local integer i = GetUnitUserData(u)
                local integer d = o
                if (GetUnitAbilityLevel(u, ABILITIES_UNIT_INDEXER) == 0 and e[i] == u) then
                    static if not LIBRARY_UnitList then
                        if (not a)then
                            set n[p[i]] = n[i]
                            set p[n[i]] = p[i]
                        endif
                    else
                        set n[p[i]] = n[i]
                        set p[n[i]] = p[i]
                        call GroupRemoveUnit(g, e[i]
                    endif

                    set o = i
                    call FireEvent(DEINDEX)
                    set o = d

                    if (lc[i] == 0) then
                        set n[i] = y
                        set y = i
                    endif
                    set e[i] = null
                endif
                set u = null
            endif
            return false
        endmethod

If you comment out the static ifs in those methods (just having unit indexer 
and minimum libraries enabled), it'll work. If they are not commented out, 
it'll crash.

This does work though
library b
globals
    private boolean c=false
endglobals
function a takes nothing returns nothing
static if LIBRARY_c then
    if (not c) then
        set c=true
    else
        set c=false
    endif
else
static if LIBRARY_a then
    if (not c) then
        set c=true
    else
        set c=false
    endif
else
    if (not c) then
        set c=true
    else
        set c=false
    endif
endif
endif
endfunction
endlibrary

I'm not sure what's breaking it ; P

Original comment by mrasolo...@gmail.com on 12 Aug 2011 at 4:52

GoogleCodeExporter commented 9 years ago
Found out what crashes it

library b
    function a takes nothing returns nothing
        static if LIBRARY_c then
            local unit u
        endif
    endfunction
endlibrary

This'll crash too

library b
    function a takes nothing returns nothing
        static if not LIBRARY_c then
            local unit u
        endif
    endfunction
endlibrary

and this

library c
endlibrary
library b
    function a takes nothing returns nothing
        static if LIBRARY_c then
            local unit u
        endif
    endfunction
endlibrary

Original comment by mrasolo...@gmail.com on 12 Aug 2011 at 4:56

GoogleCodeExporter commented 9 years ago
I confirm the bug. I'll fix it.

// rename to static if bug

Original comment by adi...@gmail.com on 12 Aug 2011 at 8:27

GoogleCodeExporter commented 9 years ago
Okay, 1.4.2.34 parse it (static if parsed well), but vJass gives error with 
modules. I knew about it, but that's another bug. I hope this bug is fixed)

http://code.google.com/p/cjass/issues/detail?id=22

Original comment by adi...@gmail.com on 12 Aug 2011 at 5:35