Forums

initializer won't work with enum values

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

initializer won't work with enum values

Postby gauthier » Sun Oct 26, 2008 8:57 am

It seems (to me) that initializer syntax has a problem with litteral enum values, see example bellow:

enum StyleType
Undefined
OldFashioned
Hype

class Model
var _style
pro style from var

class Program
def main is shared
hypeStyle = StyleType(Hype)
model = Model(style=StyleType(Hype)) #wont compile
model = Model(style=hypeStyle) #compile


giving me

Code: Select all
fail.cobra(14): error: COBRA INTERNAL ERROR / AssertException / ; sourceSite = C:\home\dev\src\dotnet\projects\cobralanguage\Source\Node.cobra:592 in Node._transformTo for object PostCallExpr-sh(12214, didBindInh=false, didBindInt=false, didStartBindImp=true, didBindImp=false, token=Token(OPEN_CALL, 'StyleType(', 'StyleType', ln 14, col 23, fail.cobra), type=EnumDecl-mi(12199, name=StyleType, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didStartBindImp=true, didBindImp=true, token=Token(ENUM, 'enum', 'enum', ln 1, col 1, fail.cobra), 12199), 12214); info       = 'superNode=PostCallExpr-sh(12217, didBindInh=false, didBindInt=false, didStartBindImp=true, isBindingImp=true, didBindImp=false, token=Token(OPEN_CALL, 'Model(', 'Model', ln 14, col 11, fail.cobra), type=nil, 12217), newNode=EnumCallExpr-sh(39103, didBindInh=false, didBindInt=false, didStartBindImp=true, didBindImp=true, token=Token(OPEN_CALL, 'StyleType(', 'StyleType', ln 14, col 23, fail.cobra), type=EnumDecl-mi(12199, name=StyleType, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didStartBindImp=true, didBindImp=true, token=Token(ENUM, 'enum', 'enum', ln 1, col 1, fail.cobra), 12199), 39103)'; this       = PostCallExpr-de(12214, didBindInh=false, didBindInt=false, didStartBindImp=true, didBindImp=false, token=Token(OPEN_CALL, 'StyleType(', 'StyleType', ln 14, col 23, fail.cobra), type=EnumDecl-mi(12199, name=StyleType, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didStartBindImp=true, didBindImp=true, token=Token(ENUM, 'enum', 'enum', ln 1, col 1, fail.cobra), 12199), expr=IdentifierExpr-sh(12213, didBindInh=false, didBindInt=false, didStartBindImp=true, didBindImp=true, token=Token(OPEN_CALL, 'StyleType(', 'StyleType', ln 14, col 23, fail.cobra), name=StyleType, type=Class-mi(1382, name=Type, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didBindImp=false, token=Token((EMPTY), '', nil, ln 1, col 1, (empty)), didBindInh=true, isGeneric=false, isGenericDef=false, needsConstruction=false, 1382), definition=EnumDecl-mi(12199, name=StyleType, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didStartBindImp=true, didBindImp=true, token=Token(ENUM, 'enum', 'enum', ln 1, col 1, fail.cobra), 12199), 12213), args=['IdentifierExpr'-'sh'(12212, 'didBindInh'=false, 'didBindInt'=false, 'didBindImp'=false, 'token'=''Token'('ID', ''Hype'', ''Hype'', ln 14, col 33, 'fail.cobra')', 'name'='Hype', 'type'=nil, 'definition'=''EnumMember'-'mi'(12198, 'name'='Hype', 'didBindInh'=false, 'didBindInt'=false, 'didBindImp'=false, 'token'=''Token'('ID', ''Hype'', ''Hype'', ln 4, col 2, 'fail.cobra')', 'value'=nil, 12198)', 12212)], hasKeywordArg=false, isForAttribute=false, 12214);     didReplace = false;
Compilation failed - 1 error, 0 warnings
Not running due to errors above.


Is it expected behaviour?

Thanks

EDIT: also, initializers won't work for member declaration, only for local variables, c# 3 to support this.
gauthier
 
Posts: 116

Re: initializer won't work with enum values

Postby Charles » Sun Oct 26, 2008 2:31 pm

A "COBRA INTERNAL ERROR" is never an expected behavior! :-)

I'll investigate.

I'm not sure what your EDIT comment means. You should be able to do this in Cobra:
button = Button(parent=panel, text='Save', autoSize=true)

If that's not what you meant, please expand and/or provide an example.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: initializer won't work with enum values

Postby gauthier » Sun Oct 26, 2008 3:24 pm

About my edit, I meant you can't do this:

class Member
var _value as int?
pro value from var

class ClassName
var member_ = Member(value=1)

class Program
def main is shared
instance = ClassName()


which give :

Code: Select all
a.cobra(5): error: COBRA INTERNAL ERROR / RequireException / ; sourceSite = C:\home\dev\src\dotnet\projects\cobralanguage\Source\Node.cobra:502 in BoxMember.bindImp for object Method-sh(22241, name=_ch_ext_init_12206, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didBindImp=false, token=Token(ID, '_ch_ext_init_12206', 'ClassName', ln 5, col 7, a.cobra), name=_ch_ext_init_12206, isNames=['shared', 'private'], parentBox=Class-mi(12201, name=ClassName, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=false, didBindImp=false, token=Token(ID, 'ClassName', 'ClassName', ln 5, col 7, a.cobra), didBindInh=true, isGeneric=false, isGenericDef=false, needsConstruction=false, 12201), returnTypeNode=Class-mi(12196, name=Member, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didBindImp=false, token=Token(ID, 'Member', 'Member', ln 1, col 7, a.cobra), didBindInh=true, isGeneric=false, isGenericDef=false, needsConstruction=false, 12196), returnType=Class-mi(12196, name=Member, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didBindImp=false, token=Token(ID, 'Member', 'Member', ln 1, col 7, a.cobra), didBindInh=true, isGeneric=false, isGenericDef=false, needsConstruction=false, 12196), implementsType=nil, 22241); info       = nil; this       = Method-de(22241, name=_ch_ext_init_12206, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didBindImp=false, token=Token(ID, '_ch_ext_init_12206', 'ClassName', ln 5, col 7, a.cobra), name=_ch_ext_init_12206, isNames=['shared', 'private'], parentBox=Class-mi(12201, name=ClassName, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=false, didBindImp=false, token=Token(ID, 'ClassName', 'ClassName', ln 5, col 7, a.cobra), didBindInh=true, isGeneric=false, isGenericDef=false, needsConstruction=false, 12201), returnTypeNode=Class-mi(12196, name=Member, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didBindImp=false, token=Token(ID, 'Member', 'Member', ln 1, col 7, a.cobra), didBindInh=true, isGeneric=false, isGenericDef=false, needsConstruction=false, 12196), returnType=Class-mi(12196, name=Member, didStartBindInh=true, didBindInh=true, didStartBindInt=true, didBindInt=true, didBindImp=false, token=Token(ID, 'Member', 'Member', ln 1, col 7, a.cobra), didBindInh=true, isGeneric=false, isGenericDef=false, needsConstruction=false, 12196), implementsType=nil, isNames=['shared', 'private'], docString=, params=['Param'(22240, "'arg0'" ('ID'), 'arg0', 'int')], requirePart=RequirePart-sh(22254, didBindInh=false, didStartBindInt=true, didBindInt=true, didBindImp=false, token=Token(ID, '_ch_ext_init_12206', 'ClassName', ln 5, col 7, a.cobra), connectToken=nil, isImplicit=true, 22254), ensurePart=EnsurePart-sh(22255, didBindInh=false, didStartBindInt=true, didBindInt=true, didBindImp=false, token=Token(ID, '_ch_ext_init_12206', 'ClassName', ln 5, col 7, a.cobra), connectToken=nil, isImplicit=true, 22255), locals=['LocalVar'(22242, "'obj'" ('ID'), 'obj', 'Member')], stmts=['AssignExpr'-'sh'(22246, 'didBindInh'=false, 'didBindInt'=false, 'didBindImp'=false, 'token'=''Token'('ASSIGN', ''='', ''ClassName'', ln 5, col 7, 'a.cobra')', 'type'=nil, 'definition'=nil, 22246), 'AssignExpr'-'sh'(22251, 'didBindInh'=false, 'didBindInt'=false, 'didBindImp'=false, 'token'=''Token'('ASSIGN', ''='', ''ClassName'', ln 5, col 7, 'a.cobra')', 'type'=nil, 'definition'=nil, 22251), 'ReturnStmt'-'sh'(22253, 'didBindInh'=false, 'didBindInt'=false, 'didBindImp'=false, 'token'=''Token'('RETURN', ''return'', ''ClassName'', ln 5, col 7, 'a.cobra')', 22253)], genericParams=[], 22241);     (not .compiler.isBindingInt or (this inherits Expr)) = false;         not .compiler.isBindingInt = false;             .compiler.isBindingInt = true;                 .compiler = Compiler(5);         (this inherits Expr) = false;
Compilation failed - 1 error, 0 warnings
Not running due to errors above.
gauthier
 
Posts: 116

Re: initializer won't work with enum values

Postby Charles » Sun Oct 26, 2008 7:24 pm

Both problems are fixed in the repository and locked down with test cases.

Nice catch. Thanks for the report.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 128 guests