Wiki

Ticket #169: static-ctor.patch

File static-ctor.patch, 2.9 KB (added by hopscc, 15 years ago)
  • Source/Members.cobra

     
    10031003                else if stmt.left inherits ThisLit and ((stmt.right inherits MemberExpr and (stmt.right to MemberExpr).name == 'init') or (stmt.right inherits CallExpr and (stmt.right to CallExpr).name == 'init'))  # CC: axe casts 
    10041004                    isThisInit = true 
    10051005            if first 
    1006                 if .isClassMember and not isBase and not isThisInit 
     1006                if .isClassMember and not isBase and not isThisInit and not stmt inherits PassStmt 
    10071007                    # structs cannot call base constructors 
    10081008                    .compiler.warning(stmt, 'The first statement of an "init" cue should be a call to another "init" in this class or the base class.') 
    10091009            else 
  • Source/BackEndClr/SharpGenerator.cobra

     
    16971697class Initializer 
    16981698    is partial 
    16991699 
     1700    def _fixupIsNames 
     1701        # suppress adding default access modifiers on static initializer 
     1702        # any access modifier in static ctor is error but that should have been caught in bind* methods 
     1703        #   we'll just cater to the default 'public' 
     1704        if 'shared' in _isNames and _isNames.count > 1 
     1705            _isNames.remove('public') 
     1706         
    17001707    def innerWriteSharpDef(sw as CurlyWriter) 
    17011708        base.innerWriteSharpDef(sw) 
    17021709        .writeSharpAttribs(sw) 
     
    17101717                        args = firstRight.args 
    17111718                        Stmt.inInitCall = true 
    17121719                        didSetInInitCall = true 
     1720        _fixupIsNames 
    17131721        .writeSharpIsNames(sw) 
    17141722        sw.write(' [.parentBox.rootName]') 
    17151723        .writeSharpParams(sw) 
  • Tests/120-classes/325-static-ctor.cobra

     
     1# This gave erroneous codegen on cue init line (ticket:169) 
     2# generating 
     3# public static Foo {} <-- 'access modifiers are not allowed on static constructors (C#)' 
     4class Foo   
     5    shared 
     6        cue init 
     7            pass 
     8 
     9        def x is private 
     10            pass     
     11 
     12        def main 
     13            pass     
     14             
     15         
     16class Foo1   
     17    cue init is shared 
     18        pass 
     19 
     20    def x is shared, private 
     21        pass     
     22 
     23    def main1 is shared 
     24        pass     
     25             
  • Developer/IntermediateReleaseNotes.text

     
    381381* Fixed: Cannot pass dynamic values to initializers. ticket:74 
    382382 
    383383* Fixed: Cobra gives an inscrutable error message for numeric for-loops that have incompatible numeric types. ticket:165 
     384 
     385* Fixed: Improper codegen for static constructors. ticket:169