Bugs ?

Hello,

I think I find some bug with VS 2008 Beta 2.

This code does not compile:

Code Block

public interface I1
{
}
public class C1<T> where T : C1<T>, I1
{
}
public class C2 : C1<C2>
{
}

The type 'ConsoleApplication11.C2' cannot be used as type parameter 'T' in the generic type or method 'ConsoleApplication11.C1'. There is no implicit reference conversion from 'ConsoleApplication11.C2' to 'ConsoleApplication11.I1'.

I must write that

Code Block

public class C2 : C1<C2>, I1

This code compile !

Code Block
public interface I1
{
string Nom { get; set; }
}
public class C1<T> where T : C1<T>, I1
{
}

Note that intellisence not allow me to define interface property.

This code does not compile

Code Block

public class C1<T> where T : C1<T>, I1
{
string I1.Nom
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
}

'ConsoleApplication12.C1.I1.Nom': containing type does not implement interface 'ConsoleApplication12.I1'

If it's not some bugs, can you explain me.

[2681 byte] By [MatthieuMEZIL] at [2008-1-10]
# 1

You get a copmile error with this code in C# 2005 as well, although the error is a bit more clear:

error CS0309: The type 'C2' must be convertible to 'I1' in order to use it as parameter 'T' in the generic type or method 'C1<T>'

PeterRitchie at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Visual C# Orcas...
# 2

I should not have this compile error, should I ?

Indeed C2 Inherits C1<C2> which implements itself I1. So C2 Implements I1.

So I don't understand why I have this compile error.

MatthieuMEZIL at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Visual C# Orcas...
# 3

C1 doesn't implement I1, the where statement is testing that T implements I1. If you want C1 to implment I1, delcare it like this:

public interface I1

{

}

public class C1<T> : I1 where T : C1<T>

{

}

PeterRitchie at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Visual C# Orcas...
# 4

I am so stupid !

Really sorry for this.

I understand well why it's ok on VS 2005, I had well written it.

MatthieuMEZIL at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Visual C# Orcas...
# 5
No problem, that's part of what the Forums are for.
PeterRitchie at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Visual C# Orcas...

Visual Studio Orcas

Site Classified