Wiki

Ticket #152: ticket152.patch

File ticket152.patch, 4.0 KB (added by eric.sellon, 15 years ago)
  • Source/CobraParser.cobra

     
    492492            if fileName.endsWith('.dll') or fileName.endsWith('.exe') 
    493493                .throwError('Do not include the extension in the file name.') 
    494494        .endOfLine 
    495         return UseDirective(token, names, fileName) 
     495        return UseDirective(token, names, fileName, true) 
    496496 
    497497    var _syntaxForClassInheritanceMsg = 'The syntax for inheritance is to put "inherits BaseClass" on the following line, indented.' 
    498498 
  • Source/Compiler.cobra

     
    761761                        # try system wide (GAC) 
    762762                        if reference.endsWith('.dll'), reference = reference[:-4] 
    763763                        referredAss = Utils.loadWithPartialName(reference) 
    764                         reference += '.dll'  # restore to original value 
     764                        if referredAss is nil, return false 
     765                        reference = referredAss.location 
    765766                # TODO: handle all the exceptions from Assembly.loadFrom 
    766767            if referredAss 
    767768                for dependency in referredAss.getReferencedAssemblies 
  • Source/NameSpace.cobra

     
    374374    var _boundNameSpace as NameSpace? 
    375375    var _fullName as String 
    376376    var _fileName as String 
     377    var _explicitUses as bool 
    377378 
    378379    cue init(token as IToken, nameParts as List<of String>) 
    379         .init(token, nameParts, '') 
     380        .init(token, nameParts, '', false) 
    380381 
    381382    cue init(token as IToken, nameParts as List<of String>, fileName as String?) 
     383        .init(token, nameParts, fileName, false) 
     384 
     385    cue init(token as IToken, nameParts as List<of String>, fileName as String?, explicitUses as bool) 
    382386        base.init(token) 
    383387        _nameParts = nameParts 
    384388        _fullName = nameParts.join('.') 
    385389        _fileName = fileName ? '' 
     390        _explicitUses = explicitUses 
    386391 
    387392    def addMinFields 
    388393        base.addMinFields 
  • Source/Phases/BindUsePhase.cobra

     
    6666        _bindUse(false) 
    6767 
    6868    def _bindUse(didAutoLoad as bool) 
     69        ignoreError = false 
    6970        curNS = .compiler.globalNS to ? 
    7071        for name in _nameParts 
    7172            curNS = curNS.subNameSpaceForName(name) 
    7273            if curNS is nil, break 
     74        if _explicitUses 
     75            # since this was an explicit uses directive, we need to make 
     76            # extra sure that we try to load a reference for it 
     77            _explicitUses = false # do not want to take this path again for this UseDirective 
     78            if curNS is not nil 
     79                # errors can be ignored because this namespace has already been loaded 
     80                ignoreError = true 
     81            curNS = nil # force reference attempt 
    7382        if curNS is nil and not didAutoLoad 
    7483            if _fileName <> '' 
    7584                if .compiler.loadReference(_fileName + '.dll') 
     
    7887                        .throwError('Cannot find namespace "[_fullName]" in library "[_fileName]".') 
    7988                    return 
    8089                else 
     90                    if ignoreError 
     91                        _bindUse(true) 
     92                        return 
    8193                    .throwError('Cannot find library file "[_fileName]".') 
    8294            else 
    8395                if _fullName.endsWith('.dll') 
     
    88100                        .throwError('Cannot find namespace "[_fullName]" in loaded library "[_fullName]".') 
    89101                    return 
    90102                else 
     103                    if ignoreError 
     104                        _bindUse(true) 
     105                        return 
    91106                    # compute how far is valid, but only here where it's needed for the error message 
    92107                    partialName = '' 
    93108                    curNS = .compiler.globalNS to ? 
  • Tests/110-basics-two/500-namespaces/201-use.cobra

     
     1use System.Windows.Forms 
     2use System.Drawing 
     3 
     4class Program 
     5 
     6    def main is shared 
     7        print Color.red