Ticket #100: final.patch
File final.patch, 3.4 KB (added by hopscc, 16 years ago) |
---|
-
Source/BackEndClr/SharpGenerator.cobra
536 536 # only have to specify the ones that are different 537 537 'shared': 'static', 538 538 'nonvirtual': '', 539 'final': '', # c# readonly only on fields, 'sealed' on classes (?) 539 540 } 540 541 sep = '' 541 542 for name in isNames … … 1447 1448 # only have to specify the ones that are different 1448 1449 'shared': 'static', 1449 1450 'nonvirtual': '', 1451 'final': 'readonly', 1450 1452 } 1451 1453 wroteNames = Set<of String>() 1452 1454 sep = '' -
Source/CobraParser.cobra
596 596 Used by: classDecl, interfaceDecl, enumDecl, indentIsDeclNames 597 597 """ 598 598 if _validIsNames is nil 599 _validIsNames = ['fake', 'extern', 'shared', 'virtual', 'nonvirtual', 'override', 'new', 'public', 'protected', 'private', 'internal', 'abstract', 'partial'] 599 _validIsNames = ['fake', 'extern', 600 'shared', 601 'virtual', 'nonvirtual', 602 'override', 'new', 603 'public', 'protected', 'private', 'internal', 604 'abstract', 605 'partial', 'final'] 600 606 names = List<of String>(_isNamesStack) 601 607 if .optional('IS') is nil 602 608 return names … … 608 614 what = 'extern' 609 615 names.add(what) 610 616 else 611 .throwError('Not expecting "[what]".') 617 if what == 'readonly' 618 _warning(.last, 'Cobra uses "final" for a runtime initialised constant not "readonly"') 619 names.add('final') 620 else 621 .throwError('Not expecting "[what]".') 612 622 if not .optional('COMMA') 613 623 if .peek.text in _validIsNames 614 624 .throwError(.peek, 'Multiple access modifiers should be separated by commas such as "[what], [.peek.text]".') -
Tests/820-errors/400-declarations/510-final.cobra
1 # Test final - runtime init constant (C# readonly) 2 class Final 3 var _year as int is final 4 5 def init(year as int) 6 _year = year 7 8 def main is shared 9 x = Final(1959) 10 x._year = 1967 # .error. cannot be assigned to 11 -
Tests/120-classes/222-fields-final.cobra
1 # Test final - runtime initialized constant (C# readonly) 2 class Final 3 var _year as int is final 4 var _nyear is final 5 6 def init(year as int) 7 _year = year 8 _nyear = year +1 9 10 def main is shared 11 x = Final(1959) 12 13 assert x._year == 1959 14 assert x._nyear == 1960 -
Tests/800-warnings/500-final.cobra
1 class Final 2 var _year as int is readonly # .warning. Cobra uses "final" for a runtime initialised constant not "readonly" 3 4 def main is shared 5 pass