[Mono-bugs] [Bug 408516] New: doubt on allowed implicit conversion from a generic argument instantiated as an interface
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Fri Jul 11 15:17:01 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=408516
Summary: doubt on allowed implicit conversion from a generic
argument instantiated as an interface
Product: Mono: Compilers
Version: SVN
Platform: Other
OS/Version: Other
Status: NEW
Severity: Normal
Priority: P5 - None
Component: C#
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: atsushi at ximian.com
QAContact: mono-bugs at lists.ximian.com
CC: mprobst at novell.com, msafar at novell.com
Found By: ---
(Copying other's report here: http://d.hatena.ne.jp/NyaRuRu/20080711/p2 )
In the last line from the following code, it tries to convert from IList<int>
to generic class Hoge<IList<int>>. gmcs allows it, but csc rejects it (CS0266).
-------
using System;
using System.Collections;
using System.Collections.Generic;
public class Hoge<T>
{
public static implicit operator Hoge<T>(T value)
{
return null;
}
}
public class Test
{
public void Foo ()
{
// OK
{
Hoge<List<int>> hoge = new List<int>();
}
// OK
{
Hoge<IList<int>> hoge = new List<int>();
}
// NG
{
IList<int> x = new List<int> ();
Hoge<IList<int>> hoge = x;
}
}
}
--------
csc reports:
test.cs(29,26): error CS0266: Cannot implicitly convert type
'System.Collections.Generic.IList<int>' to
'Hoge<System.Collections.Generic.IList<int>>'. An explicit conversion
exists (are you missing a cast?)
Generally, implicit conversion from an interface is prohibited (CS0552), and if
it is practically due to JIT efficiency, it is sort of reasonable that csc
rejects such a conversion above (probably for the purpose of generic code
sharing).
Since it smells like a bug in csc (the original reporter rather thinks so,
while I doubt in gmcs), it is posted as a feedback to Microsoft:
https://connect.microsoft.com/VisualStudioJapan/feedback/ViewFeedback.aspx?FeedbackID=355863
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list