Error in Gyro?

  • Thread starter Thread starter Ole Andre Karlson
  • Start date Start date
O

Ole Andre Karlson

hi

Still struggeling with Gyro... :)

how can this be correct?

T t = null;
gives a compile error because the compiler thinks T is a
value type.

while the test:
Type type = typeof(T);
Console.WriteLine(type.IsValueType);
gives false..

I suppose it has to do with what is known at compile time
and what is known at runtime, but why does the compiler
just asume that T is a value type if it dosn't know?

And how do I get it to understand that T is a reference
type at compile time?

code:
------------------------------
using System;

class TestClass<T>
{
public void testStuff()
{
Type type = typeof(T);
Console.WriteLine(type.IsValueType);

T t = null;
}
}

class Apple {}

class Control
{
public static void Main()
{
TestClass<Apple> t = new TestClass<Apple>();
t.testStuff();
}
}
-------------------------------
 
wrong newsgroup!
you need to use the betanews groups for vNext questions.
Sorry!
-Dino
 
Ahh.. sorry the PLDI paper on Gyro only mentioned this
group...

stupid followup question:
where do I find the betanews groups?

Ole
 
Ole,

I think Dino mistakenly thought you were an early tester of the next
version of the CLR (which also includes generics support). You can
definitely use this group to discuss Gyro.

The answer to your question can be found in docs\generics\csharp.html
in the Gyro distribution. Under the heading "'Default' values for type
parameters" it says


"No implicit conversion exists from the null type to a type parameter
V. This is because V may be instantiated as a value type, and 'null'
does not have the same, intuitive meaning that may be expected for
those types.

However, the expression V.default will be guaranteed to produce a
'default' value for the type corresponding to V. This can be
considered an explicit, unboxing conversion from the 'null' type to a
type parameter.

Note: this is not yet implemented."


So, when implemented, you'd be able to write

T t = T.default;



Mattias
 
Back
Top