Changeset 1762

Show
Ignore:
Timestamp:
11/12/08 06:03:30 (8 weeks ago)
Author:
Chuck.Esterbrook
Message:

Better error messages for C# syntax += and -= applied to events and delegates.

Location:
cobra/trunk
Files:
1 added
3 modified

Legend:

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

    r1761 r1762  
    145145For convenience, the extension methods .toPrintString and .toTechString have been added to System.Object. 
    146146 
    147 * Added improved error checking and/or error messages for `throw`, `raise` and `use`. 
     147* Added improved error checking and/or error messages for `throw`, `raise` and `use`. Also, better error messages for C# syntax += and -= applied to events and delegates. 
    148148 
    149149* Added various library methods from .NET to the primitive types such as decimal, int, char, bool, etc. These are documented on @link(http://cobra-language.com/trac/cobra/wiki/PrimitiveTypeMembers, the wiki). These include mathematical methods so you can say `x.round`, `x.round(decimals)`, `a.min(b)`, `x.sin`, `x.truncate`, etc. 
  • cobra/trunk/Source/BinaryOpExpr.cobra

    r1731 r1762  
    392392                base._bindImp 
    393393                # TODO: does NumericPromoExpr cover everything we need? 
     394                # C# and other languages use += and -= on delegates and events, but Cobra does not. 
     395                if .left.type inherits MethodSig 
     396                        # TODO: error 
     397                        pass 
     398                else if .left.type.isDescendantOf(.compiler.delegateType) 
     399                        # TODO: distinguish between events and delegates 
     400                        leftSource = .left.toCobraSource 
     401                        rightSource = .right.toCobraSource 
     402                        if not .right inherits RefExpr, rightSource = 'ref ' + rightSource 
     403                        branch .op 
     404                                on 'PLUS_EQUALS',  .throwError('Cannot use "+=". Use "listen [leftSource], [rightSource]" for events and "[leftSource] = Delegate.combine([leftSource], [rightSource])" for delegates.') 
     405                                on 'MINUS_EQUALS', .throwError('Cannot use "-=". Use "ignore [leftSource], [rightSource]" for events and "[leftSource] = Delegate.remove([rightSource])" for delegates.') 
     406                                else, .throwError('Cannot use the operator "[.token.text]" on events or delegates.') 
    394407 
    395408 
  • cobra/trunk/Source/Compiler.cobra

    r1760 r1762  
    11781178                return _libraryClass('System.Exception') 
    11791179 
     1180        def delegateType as Class 
     1181                return _libraryClass('System.Delegate') 
     1182 
    11801183        def attributeType as Box 
    11811184                return _libraryBox('System.Attribute')