Ticket #179: static-class.patch
File static-class.patch, 4.7 KB (added by hopscc, 14 years ago) |
---|
-
Source/Members.cobra
224 224 def _bindInt is override 225 225 base._bindInt 226 226 isNames = Set<of String>() 227 228 # Make them explicitly set all members shared on a shared class since while we support shared classes we 229 # dont want to encourage or make use of such classes really easy. 230 #if .parentBox.typeOf is Class and 'shared' in .parentBox.isNames and 'shared' not in _isNames 231 # .compiler.warning(this, 'All members in a shared class must also be shared.') 232 #Implicitly set all members in a shared class to be also shared 233 if .parentBox.typeOf is Class and 'shared' in .parentBox.isNames 234 _isNames.add('shared') 235 227 236 for name in _isNames 228 237 if name in isNames and not .parentBox.isFromBinaryLibrary 229 238 .compiler.warning(this, 'Duplicate modifier "[name]". You can remove it.') -
Source/BackEndClr/SharpGenerator.cobra
1039 1039 get sharpInvariantVisibility as String is abstract 1040 1040 1041 1041 def writeSharpInvariantMethod(sw as CurlyWriter) 1042 if .compiler.options['contracts'] <> 'none' 1042 if .compiler.options['contracts'] <> 'none' and not 'shared' in _isNames 1043 1043 sw.write('\nint _ih_invariantGuard;\n\n') 1044 1044 if .compiler.options['contracts'] <> 'methods' 1045 1045 return -
Tests/120-classes/250-shared-classes/200-static-class-dup.cobra
1 class MClass is shared 2 var log = '' # .warning. Duplicate modifier "shared" 3 is shared 4 5 cue init is shared # .warning. Duplicate modifier "shared" 6 .addLog('static initializer called.') 7 8 def xx as String is shared # .warning. Duplicate modifier "shared" 9 v ='foo magoo.' 10 .addLog(v) 11 return v 12 13 def addLog( s as String) is shared # .warning. Duplicate modifier "shared" 14 .log += s 15 .log += '\n' 16 17 #get getLog from log is shared 18 pro getLog as String is shared # .warning. Duplicate modifier "shared" 19 get 20 return .log 21 22 class EPoint 23 def main is shared 24 assert MClass.xx == 'foo magoo.' 25 assert MClass.getLog.trimEnd.startsWith('static initializer called') 26 assert MClass.getLog.trimEnd.endsWith('foo magoo.') -
Tests/120-classes/250-shared-classes/110-static-class-private.cobra
1 # shared on class names, implicit shared on all members, implicit private class var 2 class MClass is shared 3 var __log = '' 4 5 cue init 6 .addLog('static initializer called.') 7 8 def xx as String 9 v ='foo magoo.' 10 .addLog(v) 11 return v 12 13 def addLog(s as String) 14 __log += s 15 __log += '\n' 16 17 get getLog from __log # backing variable must be _ prefixed 18 #pro getLog from mlog # backing variable must be _ prefixed 19 #pro getLog as String 20 # get 21 # return __log 22 23 class EPoint 24 def main is shared 25 assert MClass.xx == 'foo magoo.' 26 assert MClass.getLog.trimEnd.startsWith('static initializer called') 27 assert MClass.getLog.trimEnd.endsWith('foo magoo.') 28 -
Tests/120-classes/250-shared-classes/100-static-class.cobra
1 # shared on class names, all memebers implicitly also shared 2 class MClass is shared 3 var log = '' 4 #is protected 5 6 cue init 7 .addLog('static initializer called.') 8 9 def xx as String 10 v ='foo magoo.' 11 .addLog(v) 12 return v 13 14 def addLog(s as String) 15 .log += s 16 .log += '\n' 17 18 #get getLog from mlog # backing variable must be _ prefixed 19 #pro getLog from mlog # backing variable must be _ prefixed 20 pro getLog as String 21 get 22 return .log 23 24 class EPoint 25 def main is shared 26 assert MClass.xx == 'foo magoo.' 27 assert MClass.getLog.trimEnd.startsWith('static initializer called') 28 assert MClass.getLog.trimEnd.endsWith('foo magoo.') 29