Forums

compiler error with generic method

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

compiler error with generic method

Postby gauthier » Mon Jun 01, 2009 4:38 pm

this doesn't compile:
class Sample
shared
def main
print "hello"
def method<of T>(doStuff as Func<of T>) as Response<of T>
result = doStuff()
return Response<of T>(value=result)

class Response<of T>
pro value from var as T


compiled with
Code: Select all
cobra -ref:"C:\WINDOWS\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll" test

c:\tmp\cobratickets\test.cobra(1): error: The type or namespace name "T" could not be found (are you missing a using directive or an assembly reference?)
Compilation failed - 1 error, 0 warnings
Not running due to errors above.


any idea what is wrong?
gauthier
 
Posts: 116

Re: compiler error with generic method

Postby Charles » Mon Jun 01, 2009 4:48 pm

I'll have to take a look.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: compiler error with generic method

Postby Charles » Mon Jun 01, 2009 5:03 pm

The bug is that when you use extended initialization on a generic class:
Response<of T>(value=result)
the code generation is done wrong and the C# compiler errors on the bad code. The temporary work around is to break it up like:
r = Response<of T>()
r.value = result
which is the same semantics.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: compiler error with generic method

Postby gauthier » Mon Jun 01, 2009 5:24 pm

thanks, the work around is welcome
gauthier
 
Posts: 116

Re: compiler error with generic method

Postby Charles » Mon Jun 01, 2009 7:55 pm

Well technically the bug is triggered by using extended initialization inside a generic method, but regardless, it is now fixed in the repository with a test case to lock it in. 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 75 guests