Page 1 of 1

Problem with TypeName<of T>.getType in attributes

PostPosted: Fri Sep 18, 2009 11:25 am
by gauthier
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.

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

PostPosted: Sat Sep 19, 2009 3:06 am
by Charles
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

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

PostPosted: Tue Nov 17, 2009 3:25 am
by Charles
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.