Wiki

Ticket #34: var-isnames-assign.patch

File var-isnames-assign.patch, 2.6 KB (added by hopscc, 16 years ago)
  • Source/CobraParser.cobra

     
    11041104            .throwError('Class variables must start with lowercase letters (after the underscore(s)) to distinguish them from other types of identifiers.[sugg]') 
    11051105        type = if(.optional('AS'), .typeId, nil) to ITypeProxy? 
    11061106        if .optional('ASSIGN') 
     1107            oldState = .opPrecSuppress( 'IS', 'ISNOT') 
    11071108            initExpr = .expression to ? 
     1109            .opPrecRestore(oldState) 
    11081110        else 
    11091111            initExpr = nil 
    11101112            if type is nil 
     
    23852387            'OLD':   _binaryOpPrec['STARSTAR']+1, 
    23862388        } 
    23872389 
     2390    # suppress named entries in op precedence table 
     2391    def opPrecSuppress( ops as vari String) as IDictionary<of String, int> is shared 
     2392        require ops.length >0 
     2393        ensure oldState.count == ops.length 
     2394        oldState = Dictionary<of String, int>() 
     2395        for op in ops 
     2396            oldState[op] = _binaryOpPrec[op] 
     2397            _binaryOpPrec[op] = -1       
     2398        return oldState 
     2399             
     2400    # restore to values before suppressed 
     2401    def opPrecRestore( prev as IDictionary<of String, int>) is shared 
     2402        require prev.count >0 
     2403        for op in prev.keys 
     2404            _binaryOpPrec[op] = prev[op] 
     2405         
    23882406    var _inExpression as int 
    23892407     
    23902408    def expression as Expr 
  • Tests/120-classes/220-fields-assign-isnames.cobra

     
     1class Point 
     2 
     3    var x as int  # no underscore 
     4    var y as int 
     5    var s as String = '' is public # a non-nil reference type assigned at decl 
     6 
     7    def init 
     8        assert .s == '' 
     9        .s = 'x' 
     10 
     11    get sum as int 
     12        return .x + .y 
     13 
     14class Program 
     15 
     16    def main is shared 
     17        p = Point() 
     18        assert p.s =='x' 
     19        p.x = 2 
     20        p.y = 3 
     21        assert p.x + p.y == 5 
     22        assert p.sum == 5 
  • Developer/IntermediateReleaseNotes.text

     
    5353* Fixed: Method return types from generics in DLLs are always considered nilable even if the generic parameter was not (such as `bool`). ticket:22 
    5454 
    5555* Fixed: Assignments (and other side effects) can appear in assert conditions even though they might be excluded during compilation or run-time. ticket:4 (hopscc) 
     56 
     57* Fixed: compile error if attempt declare a class var with both isnames setting and assignment (hopscc)