                 i = 0
                 longestMatchingFlag = null
 
-            while i < ext.length
-                for flag of currentMatchingFlags when flag[i] isnt ext[i]
+            while i < flagName.length
+                for flag of currentMatchingFlags when flag[i] isnt flagName[i]
                     delete currentMatchingFlags[flag]
                     --nMatching
 


                if nMatching is 1
                    flagMatching = _.keys(currentMatchingFlags)[0]
                    return invalidFlag ext if flagMatching[i..] isnt ext[i...flagMatching.length]
                    ext = ext[flagMatching.length..]
                    resetInfo()
                    flagString.pushBack(COMPILER_FLAGS[flagMatching])
                else if nMatching is 0
                    if longestMatchingFlag?
                        flagString.pushBack(COMPILER_FLAGS[longestMatchingFlag])
                        ext = ext[longestMatchingFlag.length..]
                        resetInfo()
                    else
                        return invalidFlag ext

            if ext.length > 0
                if longestMatchingFlag?
                    flagString.pushBack(COMPILER_FLAGS[longestMatchingFlag])
                else
                    return invalidFlag ext

        flagString.pushBack(@flagsByProgram.all ? "",
                            @flagsByProgram[programIndex] ? "")


        ext = ext[1..].toLowerCase() # Get rid of the dot and put to lowercase

        flagString = new ListString()
        for flagName in ext.split('.')
            initialMatching = _.size(COMPILER_FLAGS)
            currentMatchingFlags = {}
            i = longestMatchingFlag = nMatching = undefined

            do resetInfo = ->
