Ticket #238: struct-init.patch
File struct-init.patch, 2.6 KB (added by hopscc, 14 years ago) |
---|
-
Source/BackEndClr/SharpGenerator.cobra
1538 1538 if _initExpr 1539 1539 sw.write(' = ') 1540 1540 _initExpr.writeSharpDef(sw) 1541 else if .type.isReference and not .type.nonNil inherits GenericParam1541 else if _canInitDefault 1542 1542 sharpInit = .type.sharpInit 1543 1543 if sharpInit.length 1544 1544 sw.write(' = ') 1545 1545 sw.write(sharpInit) 1546 1546 sw.write(';\n') 1547 1548 def _canInitDefault as bool 1549 # In C# struct members can't be explicitly initted on declaration 1550 if .compiler.boxStack.peek.sharpKeyWord == 'struct', return false 1551 return .type.isReference and not .type.nonNil inherits GenericParam 1552 1547 1553 1548 1549 1554 class AbstractMethod 1550 1555 is partial 1551 1556 -
Tests/140-structs/210-struct-init.cobra
1 # Test fix for Ticket:238. Default InitExprs not allowed in structs 2 #struct-init.cobra(8): error: "St.Name": cannot have instance field initializers in structs (C#) 3 #struct-init.cobra(19): error: "St1.X": cannot have instance field initializers in structs (C#) 4 class XX 5 pass 6 7 struct St 8 var name as String 9 var n as int 10 11 cue init(name as String, n as int) 12 .name = name 13 .n = n 14 15 # def toString as String is override 16 # return 'St(name=[.name], n=[.n])' 17 18 struct St1 19 var x as XX 20 var n as int 21 22 cue init(x as XX, n as int) 23 .x = x 24 .n = n 25 26 # def toString as String is override 27 # return 'St(x=[.x], n=[.n])' 28 29 class Entry 30 def main is shared 31 x = St('xxx', 10) 32 assert x.name == 'xxx' and x.n == 10 33 34 xx = XX() 35 x1 = St1(xx, 11) 36 assert x1.x == xx and x1.n == 11 37 38 # declare only and pack/unpack members explicitly 39 xa as St 40 #pack 41 xa.name = 'aaa' 42 xa.n = 12 43 #unpack 44 xa_name = xa.name 45 xa_n = xa.n 46 assert xa_name == 'aaa' and xa_n == 12 -
Developer/IntermediateReleaseNotes.text
477 477 * Fixed: File and line number are duplicated in some compiler error messages. ticket:212 478 478 479 479 * Fixed: Some invariants cause an internal error. ticket:248 480 481 * Fixed: Bad codegen for structs containing strings (ref types). ticket:238