use System.Drawing
use System.Windows.Forms
class Exercise inherits System.Windows.Forms.Form
var rchNote as RichTextBox
#var chNote as TextBox
cue init
base.init
.initializeComponent
def initializeComponent is private
.rchNote = RichTextBox()
.controls.add(.rchNote)
#.chNote = TextBox()
#.controls.add(.chNote)
class Program
def main is shared
System.Windows.Forms.Application.run(Exercise())
throws an exception in the cobra compiler - if change RichTextBox to TextBox (or any other Forms control) it doesnt.
exception is
- Code: Select all
782 xx:...hops/src/cobra/Tst> cobc1 rtb.cobra
Unhandled Exception: System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Compiler.AddTypeForClrType(IType type, Type clrType) in c:\home\hops\src\cobra\wkspace1\Source\Compiler.cobra:line 139
at ClrTypeProxy._realTypeWithCache(Type clrType) in c:\home\hops\src\cobra\wkspace1\Source\TypeProxies.cobra:line 162
at ClrTypeProxy.get_RealType() in c:\home\hops\src\cobra\wkspace1\Source\TypeProxies.cobra:line 157
at NilableTypeProxy.get_RealType() in c:\home\hops\src\cobra\wkspace1\Source\TypeProxies.cobra:line 86
at AbstractLocalVar._resolveType() in c:\home\hops\src\cobra\wkspace1\Source\Vars.cobra:line 129
at AbstractLocalVar._bindInt() in c:\home\hops\src\cobra\wkspace1\Source\Vars.cobra:line 115
at Param._bindInt() in c:\home\hops\src\cobra\wkspace1\Source\Vars.cobra:line 206
at Node.BindInt() in c:\home\hops\src\cobra\wkspace1\Source\Node.cobra:line 504
at AbstractMethod._bindInt() in c:\home\hops\src\cobra\wkspace1\Source\Members.cobra:line 831
at Method._bindInt() in c:\home\hops\src\cobra\wkspace1\Source\Members.cobra:line 1175
at Node.BindInt() in c:\home\hops\src\cobra\wkspace1\Source\Node.cobra:line 504
at Box._bindInt() in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line
657
at ClassOrStruct._bindInt() in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line 1121
at Class._bindInt() in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line 1261
at Node.BindInt() in c:\home\hops\src\cobra\wkspace1\Source\Node.cobra:line 504
at Box.BindInt() in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line 623
at Box.__prepLibraryBox() in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line 768
at Box._prepLibraryBox() in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line 752
at Class.IsDescendantOf(IType type) in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line 1178
at Container`1.IsAssignableTo(IType type) in c:\home\hops\src\cobra\wkspace1\Source\Container.cobra:line 250
at Box.IsAssignableTo(IType type) in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line 804
at Container`1.IsAssignableTo(IType type) in c:\home\hops\src\cobra\wkspace1\Source\Container.cobra:line 249
at Box.IsAssignableTo(IType type) in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line 804
at Expr.CanBeAssignedTo(IType type) in c:\home\hops\src\cobra\wkspace1\Source\Expr.cobra:line 127
at MemberOverload.ComputeBestOverload(List`1 args, List`1 genericArgTypes, Boolean strictBindChecking) in c:\home\hops\src\cobra\wkspace1\Source\Members.cobra:line 1475
at CallExpr._bindImp() in c:\home\hops\src\cobra\wkspace1\Source\Expr.cobra:line 598
at Node.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Node.cobra:line 562
at Stmt.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Statements.cobra:line 108
at Expr.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Expr.cobra:line 187
at BinaryOpExpr._bindImp() in c:\home\hops\src\cobra\wkspace1\Source\BinaryOpExpr.cobra:line 124
at DotExpr._bindImp() in c:\home\hops\src\cobra\wkspace1\Source\BinaryOpExpr.cobra:line 651
at Node.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Node.cobra:line 562
at Stmt.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Statements.cobra:line 108
at Expr.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Expr.cobra:line 187
at BinaryOpExpr.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\BinaryOpExpr.cobra:line 105
at AbstractMethod._bindImp() in c:\home\hops\src\cobra\wkspace1\Source\Members.cobra:line 866
at Method._bindImp() in c:\home\hops\src\cobra\wkspace1\Source\Members.cobra:line 1180
at Node.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Node.cobra:line 562
at BoxMember.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Members.cobra:line 256
at Box._bindImp() in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line
732
at ClassOrStruct._bindImp() in c:\home\hops\src\cobra\wkspace1\Source\Boxes.cobra:line 1124
at Node.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Node.cobra:line 562
at NameSpace._bindImp() in c:\home\hops\src\cobra\wkspace1\Source\NameSpace.cobra:line 234
at Node.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Node.cobra:line 562
at CobraModule._bindImp() in c:\home\hops\src\cobra\wkspace1\Source\Module.cobra:line 97
at Node.BindImp() in c:\home\hops\src\cobra\wkspace1\Source\Node.cobra:line 562
at BindImplementationPhase.InnerRun() in c:\home\hops\src\cobra\wkspace1\Source\Phases\phases\BindImplementationPhase.cobra:line 18
at Phase.Run() in c:\home\hops\src\cobra\wkspace1\Source\Phases\phases\Phase.cobra:line 75
at Compiler.RunPhase(Phase phase) in c:\home\hops\src\cobra\wkspace1\Source\Compiler.cobra:line 317
at Compiler._compileFilesNamed(IList`1 paths, Boolean writeTestInvocation, Predicate`1 stopCompilation) in c:\home\hops\src\cobra\wkspace1\Source\Compiler.cobra:line 376
at Compiler.CompileFilesNamed(IList`1 paths, Boolean writeTestInvocation, Predicate`1 stopCompilation) in c:\home\hops\src\cobra\wkspace1\Source\Compiler.cobra:line 339
at CommandLine.DoCompile(List`1 paths, Boolean willPrintSuccessMsg, Boolean writeTestInvocation, Predicate`1 stopCompilation) in c:\home\hops\src\cobra\wkspace1\Source\CommandLine.cobra:line 649
at CommandLine.DoRun(List`1 paths) in c:\home\hops\src\cobra\wkspace1\Source\CommandLine.cobra:line 734
at CommandLine.Run(List`1 args) in c:\home\hops\src\cobra\wkspace1\Source\CommandLine.cobra:line 610
at CommandLine.Run() in c:\home\hops\src\cobra\wkspace1\Source\CommandLine.cobra:line 550
at CobraMain.Main() in c:\home\hops\src\cobra\wkspace1\Source\cobra.cobra:line 17
(null)
783 xx:...hops/src/cobra/Tst>
This patch fixes the compiler exception though I'm not sure its doing the right thing...
- Code: Select all
Index: BackEndClr/ScanClrType.cobra
===================================================================
--- BackEndClr/ScanClrType.cobra (revision 2282)
+++ BackEndClr/ScanClrType.cobra (working copy)
@@ -136,7 +136,8 @@
return if(_clrTypeToType.containsKey(clrType), _clrTypeToType[clrType], nil)
def addTypeForClrType(type as IType, clrType as System.Type)
- _clrTypeToType.add(clrType, type)
+ if not _clrTypeToType.containsKey(clrType)
+ _clrTypeToType.add(clrType, type)