Page 1 of 1

compiler error with generic method

PostPosted: Mon Jun 01, 2009 4:38 pm
by gauthier
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?

Re: compiler error with generic method

PostPosted: Mon Jun 01, 2009 4:48 pm
by Charles
I'll have to take a look.

Re: compiler error with generic method

PostPosted: Mon Jun 01, 2009 5:03 pm
by Charles
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.

Re: compiler error with generic method

PostPosted: Mon Jun 01, 2009 5:24 pm
by gauthier
thanks, the work around is welcome

Re: compiler error with generic method

PostPosted: Mon Jun 01, 2009 7:55 pm
by Charles
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.