[nem-bug] [Nemerle 0000729]: complex use of Co/contravariance for
generic interfaces / delegates
feedback at nemerle.org
feedback at nemerle.org
Sun Aug 6 16:00:00 CEST 2006
The following issue has been RESOLVED.
======================================================================
<http://nemerle.org/bugs/view.php?id=729>
======================================================================
Reported By: Tobias
Assigned To: nazgul
======================================================================
Project: Nemerle
Issue ID: 729
Category: Compiler
Reproducibility: always
Severity: minor
Priority: normal
Status: resolved
Resolution: fixed
Fixed in Version:
======================================================================
Date Submitted: 08-05-2006 18:25 CEST
Last Modified: 08-06-2006 16:00 CEST
======================================================================
Summary: complex use of Co/contravariance for generic
interfaces / delegates
Description:
#pragma indent
using System
public interface ICovariantEnumerator [+T]
{
MoveNext () : bool;
Current : T { get; }
}
public interface ICovariantEnumerable [+T]
{
GetEnumerator () : ICovariantEnumerator [T];
SetEnumerator(e : ICovariantEnumerator [T]) : void;
}
[Record] \
public class Enumerator [T] : ICovariantEnumerator [T]
{
enu : System.Collections.Generic.IEnumerator [T];
public MoveNext () : bool
{
enu.MoveNext ();
}
public Current : T {
get { enu.Current }
}
}
public class Enumerable [T] : ICovariantEnumerable [T]
{
mutable enu : ICovariantEnumerator [T];
public GetEnumerator () : ICovariantEnumerator [T]
{
enu;
}
public SetEnumerator (e : ICovariantEnumerator [T]) : void
{
enu = e;
}
}
def int_list = Enumerable() : ICovariantEnumerable[int]
def string_list = ["a", "b", "c"]
def object_list = int_list : ICovariantEnumerable[object]
def e_s = Enumerator(string_list.GetEnumerator()) :
ICovariantEnumerator[string]
def e_o = e_s : ICovariantEnumerator[object]
object_list.SetEnumerator(e_o)
foreach(i in int_list) {
Console.WriteLine(i)
}
_ = Console.ReadLine()
Compiles but you get
TypeLoadException:
Could not load type 'ICovariantEnumerable`1' from assembly 'Test,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because a covariant
or contravariant type parameter was used illegally in the signature for an
argument in method 'SetEnumerator'.
when running
======================================================================
----------------------------------------------------------------------
nazgul - 08-06-06 16:00
----------------------------------------------------------------------
Thanks, I missed the point of "inverting" the set of variance signs (S) in
the implementation. :)
Fixed on trunk (r6487).
Issue History
Date Modified Username Field Change
======================================================================
08-05-06 18:25 Tobias New Issue
08-05-06 18:25 Tobias File Added: cocontra.patch
08-06-06 16:00 nazgul Status new => resolved
08-06-06 16:00 nazgul Resolution open => fixed
08-06-06 16:00 nazgul Assigned To => nazgul
08-06-06 16:00 nazgul Note Added: 0001397
======================================================================
More information about the bugs
mailing list