Ticket #34: var-isnames-assign.patch
File var-isnames-assign.patch, 2.6 KB (added by hopscc, 16 years ago) |
---|
-
Source/CobraParser.cobra
1104 1104 .throwError('Class variables must start with lowercase letters (after the underscore(s)) to distinguish them from other types of identifiers.[sugg]') 1105 1105 type = if(.optional('AS'), .typeId, nil) to ITypeProxy? 1106 1106 if .optional('ASSIGN') 1107 oldState = .opPrecSuppress( 'IS', 'ISNOT') 1107 1108 initExpr = .expression to ? 1109 .opPrecRestore(oldState) 1108 1110 else 1109 1111 initExpr = nil 1110 1112 if type is nil … … 2385 2387 'OLD': _binaryOpPrec['STARSTAR']+1, 2386 2388 } 2387 2389 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 2388 2406 var _inExpression as int 2389 2407 2390 2408 def expression as Expr -
Tests/120-classes/220-fields-assign-isnames.cobra
1 class 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 14 class 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
53 53 * Fixed: Method return types from generics in DLLs are always considered nilable even if the generic parameter was not (such as `bool`). ticket:22 54 54 55 55 * 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)