Ticket #264: tkt264.patch
File tkt264.patch, 3.1 KB (added by hopscc, 12 years ago) |
---|
-
Source/BackEndClr/SharpGenerator.cobra
3636 3636 if expr inherits TypeExpr 3637 3637 if expr.containedType inherits ArrayType 3638 3638 # arrays 3639 sw.write('new ') 3640 sw.write((expr.containedType to ArrayType).theWrappedType.sharpRef) 3641 sw.write(r'[') 3642 .writeSharpArgs(sw) 3643 sw.write(r']') 3639 _writeNewCall(sw, nil, (expr.containedType to ArrayType).theWrappedType.sharpRef, false) 3644 3640 else 3645 sw.write('new ') 3646 expr.writeSharpDef(sw) 3647 sw.write('(') 3648 .writeSharpArgs(sw) 3649 sw.write(')') 3641 _writeNewCall(sw, expr, '', true) 3650 3642 else if expr inherits IdentifierExpr 3651 3643 if expr.isTypeReference 3652 sw.write('new ') 3653 expr.writeSharpDef(sw) 3654 sw.write('(') 3655 .writeSharpArgs(sw) 3656 sw.write(')') 3644 _writeNewCall(sw, expr, '', true) 3657 3645 else if expr.receiverType inherits GenericParam # TODO: shouldn't expr.isTypeReference above have caught this? 3658 sw.write('new [expr.receiverType.sharpRef](') 3659 .writeSharpArgs(sw) 3660 sw.write(')') 3646 _writeNewCall(sw, nil, expr.receiverType.sharpRef, true) 3661 3647 else if expr.type.nonNil.isDescendantOf(.compiler.delegateType) 3662 3648 isMethodSig = true 3663 3649 else if expr.type.isSystemTypeClass or _type.isDynamic … … 3686 3672 if defi.type.isDynamic 3687 3673 what = '(System.Type)' + what 3688 3674 # TODO: could speed this up. see http://ayende.com/Blog/archive/2008/02/27/Creating-objects--Perf-implications.aspx 3689 sw.write('System.Activator.CreateInstance([what]') 3675 sw.write('System.Activator.CreateInstance(') 3676 if what == r'[]' # Indexer - something like myList[idx]() 3677 expr.writeSharpDef(sw) 3678 else 3679 sw.write(what) 3690 3680 .writeSharpArgs(sw, ', ') 3691 3681 sw.write(')') 3692 3682 if parens, sw.write(')') 3693 3683 3684 def _writeNewCall(sw as CurlyWriter, expr as Expr?, exprStr as String, isInvocation as bool) 3685 require expr or exprStr.length >0 3686 delim = if(isInvocation, '()', r'[]') # invocation or index deref 3687 sw.write('new ') 3688 if expr, expr.writeSharpDef(sw) 3689 else, sw.write(exprStr) 3690 sw.write(delim[0]) 3691 .writeSharpArgs(sw) 3692 sw.write(delim[1]) 3693 3694 3694 def writeSharpArgs(sw as CurlyWriter) 3695 3695 .writeSharpArgs(sw, '') 3696 3696 -
Tests/320-misc-two/855-indexed-postcall.cobra
1 class A 2 def blah 3 print "A!" 4 5 class B 6 def blah 7 print "B!" 8 9 class C 10 def blah 11 print "C!" 12 13 14 class Program 15 def main 16 myList = [A, B, C] 17 for i, type in myList.numbered 18 # This works: 19 type = myList[i] 20 type().blah 21 # This failed at compile time: 22 myList[i]().blah 23 24 for i in 0: myList.count 25 myList[i]().blah