Changeset 1767

Show
Ignore:
Timestamp:
11/15/08 23:31:17 (8 weeks ago)
Author:
Chuck.Esterbrook
Message:

Fixed: Cannot properly invoke delegates whose delegate types come from binary libraries.
Improved error messages regarding the use of += and -= with events and delegates.

Location:
cobra/trunk
Files:
1 added
6 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Developer/IntermediateReleaseNotes.text

    r1762 r1767  
    222222 
    223223* Fixed: No warning for derived methods that are not marked "override" or "new" when the parameters differ by being nilable (String?) or not (String). ticket:59 
     224 
     225* Fixed: Cannot properly invoke delegates whose delegate types come from binary libraries. 
  • cobra/trunk/Source/BackEndClr/SharpGenerator.cobra

    r1766 r1767  
    22Eventually this file will contain all C# code generation. 
    33In the future, you can expect (or contribute!) alternate code generators such as IL, JVM and Objective-C. 
     4 
     5There should be not use .throwError, or recording of warnings, etc. in this file. 
     6All of that happens during .bindFoo phases. 
    47""" 
    58 
     
    33713374                                        .writeSharpArgs(sw) 
    33723375                                        sw.write(')') 
    3373                                 else if expr.type inherits MethodSig or (expr.type inherits NilableType and (expr.type to NilableType).theWrappedType inherits MethodSig) 
     3376                                else if expr.type.isDescendantOf(.compiler.delegateType) 
     3377                                        isMethodSig = true 
     3378                                else if expr.type inherits NilableType and (expr.type to NilableType).theWrappedType.isDescendantOf(.compiler.delegateType) 
    33743379                                        isMethodSig = true 
    33753380                                else if expr.type.isSystemTypeClass or _type.isDynamic 
    33763381                                        isDynamic = true 
    33773382                                else 
    3378                                         assert false, expr  # TODO: .throwError 
     3383                                        assert false, expr 
    33793384                        else if expr inherits IndexExpr 
    3380                                 if expr.type inherits MethodSig 
     3385                                if expr.type.isDescendantOf(.compiler.delegateType) 
    33813386                                        isMethodSig = true 
    33823387                                else if expr.type.isSystemTypeClass or _type.isDynamic 
    33833388                                        isDynamic = true 
    33843389                                else 
    3385                                         assert false, expr  # TODO: .throwError 
     3390                                        assert false, expr 
    33863391                        else 
    3387                                 assert false, expr  # TODO: .throwError 
     3392                                assert false, expr 
    33883393                        if isMethodSig 
    3389                                 expr.writeSharpDef(sw) 
     3394                                expr.writeSharpDef(sw, false) 
    33903395                                sw.write('(') 
    33913396                                .writeSharpArgs(sw) 
  • cobra/trunk/Source/BinaryOpExpr.cobra

    r1766 r1767  
    384384                        pass 
    385385                else if .left.type.isDescendantOf(.compiler.delegateType) 
    386                         # TODO: distinguish between events and delegates 
    387386                        leftSource = .left.toCobraSource 
    388387                        rightSource = .right.toCobraSource 
    389388                        if not .right inherits RefExpr, rightSource = 'ref ' + rightSource 
    390389                        branch .op 
    391                                 on 'PLUS_EQUALS',  .throwError('Cannot use "+=". Use "listen [leftSource], [rightSource]" for events and "[leftSource] = Delegate.combine([leftSource], [rightSource])" for delegates.') 
    392                                 on 'MINUS_EQUALS', .throwError('Cannot use "-=". Use "ignore [leftSource], [rightSource]" for events and "[leftSource] = Delegate.remove([rightSource])" for delegates.') 
    393                                 else, .throwError('Cannot use the operator "[.token.text]" on events or delegates.') 
    394  
     390                                on 'PLUS_EQUALS' 
     391                                        msg = 'Cannot use "+=". ' 
     392                                        if .left.definition inherits BoxEvent, msg += 'Use "listen [leftSource], [rightSource]" for events.' 
     393                                        else, msg += 'Use "[leftSource] = Delegate.combine([leftSource], [rightSource])" for delegates.' 
     394                                on 'MINUS_EQUALS' 
     395                                        msg = 'Cannot use "-=". ' 
     396                                        if .left.definition inherits BoxEvent, msg += 'Use "ignore [leftSource], [rightSource]" for events.' 
     397                                        else, msg += 'Use "[leftSource] = Delegate.remove([rightSource])" for delegates.' 
     398                                else 
     399                                        msg = 'Cannot use the operator "[.token.text]" on events or delegates.' 
     400                        .throwError(msg) 
    395401 
    396402class AugAssignBitwiseExpr 
  • cobra/trunk/Source/Expr.cobra

    r1766 r1767  
    15701570                        if exprType inherits NilableType 
    15711571                                exprType = exprType.theWrappedType 
    1572                         if exprType inherits MethodSig  # TODO: probably still need to handle case of a method sig coming from a DLL 
     1572                        if exprType inherits MethodSig 
    15731573                                _type = exprType.returnType 
     1574                        else if exprType.isDescendantOf(.compiler.delegateType) 
     1575                                member = exprType.memberForName('invoke') 
     1576                                if member inherits Method 
     1577                                        _type = member.resultType 
     1578                                else 
     1579                                        .throwError('Cannot find a single "invoke" method for "_eventType.name".') 
    15741580                        else if expr.receiverType and expr.receiverType.isSystemTypeClass 
    15751581                                _type = .compiler.dynamicType 
  • cobra/trunk/Source/Members.cobra

    r1758 r1767  
    374374                        _handlerType = _handlerTypeProxy.realType 
    375375                # TODO: error check that _handlerType is a delegate 
    376                 # _handlerType.isDescendantOf(.compiler.libraryType('System.Delegate')) 
     376                # _handlerType.isDescendantOf(.compiler.delegateType) 
    377377 
    378378 
  • cobra/trunk/Source/Statements.cobra

    r1763 r1767  
    915915                                assert expr.potentialType 
    916916                                _eventType = expr.potentialType 
    917                                 if _eventType.isDescendantOf(.compiler.libraryType('System.Delegate')) or _eventType inherits MethodSig 
     917                                if _eventType.isDescendantOf(.compiler.delegateType) 
    918918                                        pass 
    919919                                else if _eventType.isDescendantOf(.compiler.exceptionType)