Ticket #205: prop-from-var-fallback.patch
File prop-from-var-fallback.patch, 3.8 KB (added by hopscc, 14 years ago) |
---|
-
Source/CobraParser.cobra
1670 1670 # TODO: if the var was declared separately, then warn about redeclaring its type, or error if the type is different 1671 1671 possibleVarDef = .curBox.declForName(varName) 1672 1672 if not possibleVarDef 1673 if not initExpr and not declVarType 1673 if initExpr or declVarType 1674 varDef = BoxVar(token, token, .curBox, varName, declVarType, List<of String>(_isNamesStack), initExpr, nil, 'Automatic backing var for property "[name]".') 1675 .curBox.addDecl(varDef) 1676 return varDef 1677 if not varName.startsWith('_') or varName.startsWith('__') 1674 1678 .throwError('There is no variable named "[varName]" to match the property "[name]".') 1675 varDef = BoxVar(token, token, .curBox, varName, declVarType, List<of String>(_isNamesStack), initExpr, nil, 'Automatic backing var for property "[name]".') 1676 .curBox.addDecl(varDef) 1677 return varDef 1679 # tried looking for '_varName' now try '__varName' 1680 varName0, varName = varName, '_' + varName 1681 possibleVarDef = .curBox.declForName(varName) 1682 if not possibleVarDef 1683 .throwError('There is no variable named "[varName0]" or "[varName]" to match the property "[name]".') 1678 1684 1679 1685 if possibleVarDef inherits BoxVar 1680 1686 varDef = possibleVarDef -
Tests/120-classes/500-properties/123-properties-from.cobra
1 # Test 'name from var' uses '__name' if no '_name' 2 class Point 3 4 # TODO: cover `pro` and `set` 5 # TODO: verify _x is protected and __y is private 6 7 var _x as int # protected 8 var __y as int # private 9 10 var _xy = 200 11 var __xy = 220 12 13 cue init 14 base.init 15 _x = 100 16 __y = 101 17 18 get x from var # typical property with explicit _named var backing 19 20 get y from var # no _y var but there is __y 21 22 pro xy from var # map onto _xy 23 24 def moveBy(dx as int, dy as int) 25 _x += dx 26 __y += dy 27 28 def main is shared 29 p = Point() 30 assert p.x == 100 31 assert p.y == 101 32 33 assert p.xy == 200 34 assert p._xy == p.xy 35 p.xy += 2 36 assert p.xy == 202 37 assert p._xy == p.xy 38 assert p.__xy == 220 39 assert p.xy <> p.__xy 40 41 p.moveBy(2,2) 42 assert p.x == 102 43 assert p.y == 103 44 assert p._x == p.x 45 assert p.__y == p.y -
Tests/120-classes/500-properties/123-properties-from-error.cobra
1 # Test 'name from var' fails if no '_name' or '__name' 2 class Point 3 4 var _x as int # protected 5 var __y as int # private 6 7 var _xy = 200 8 var __xy = 220 9 10 cue init 11 base.init 12 _x = 100 13 __y = 101 14 15 pro xyz from var 16 # .error. no variable named "_xyz" or "__xyz" -
Developer/IntermediateReleaseNotes.text
467 467 * Fixed: The expression `nil is x`, where `x` is a nilable type, generates a false error message. 468 468 469 469 * Fixed: Only the last `test` of a series of tests is included in the compiler's output. 470 471 * Made properties using 'from var' search for a __name if the _name search fails 472 before emitting an error. ticket:205