Forums

Problem with TypeName<of T>.getType in attributes

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

Problem with TypeName<of T>.getType in attributes

Postby gauthier » Fri Sep 18, 2009 11:25 am

This looks like a corner corner case:

class FooAttribute
inherits Attribute

pro bar from var as Type?

class WithGeneric<of T>
pass

class WithAttribute

pro foo from var as int?
has FooAttribute(bar = WithGeneric<of int>.getType)

class Program
shared
def main
pass


Code: Select all
test.cobra(14): error: The definition for "WithGeneric<of>.getType" is not a type.
Compilation failed - 1 error, 0 warnings
Not running due to errors above.
gauthier
 
Posts: 116

Re: Problem with TypeName<of T>.getType in attributes

Postby Charles » Sat Sep 19, 2009 3:06 am

Sorry about that. Here's a workaround:
class FooAttribute inherits Attribute

pro bar from var as Type?

class WithGeneric<of T>
pass

class WithAttribute

pro foo from var as int?
has FooAttribute(bar = sharp'typeof(WithGeneric<int>)')

class Program
def main
pass
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Problem with TypeName<of T>.getType in attributes

Postby Charles » Tue Nov 17, 2009 3:25 am

In the current/trunk version of Cobra, you can skip the use of "sharp" and just leave the .getType off, which is how I would normally write the code anyway:
has FooAttribute(bar = WithGeneric<of int>)

Cobra lets you pass types directly, although this was previously broken for some cases with generics, but is now fixed.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 41 guests