Error in Gyro?

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();
}
}
-------------------------------
 
D

Dino Chiesa [Microsoft]

wrong newsgroup!
you need to use the betanews groups for vNext questions.
Sorry!
-Dino
 
O

Ole Andre Karlson

Ahh.. sorry the PLDI paper on Gyro only mentioned this
group...

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

Ole
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top