[Mono-dev] c# compiler problem with generics and derived interfaces

matteo tesser matteo.tesser at gmail.com
Wed Jun 16 08:14:16 EDT 2010


Hello,
I cannot compile the code reported below with mono 2.6.4 (which
compiles fine using visual studio 2008).

By executing  gmcs MatrixArray.cs (see below or attached file)  I
obtain the following errors:

MatrixArray.cs(40,24): error CS0021: Cannot apply indexing with [] to
an expression of type `T'
MatrixArray.cs(44,17): error CS0021: Cannot apply indexing with [] to
an expression of type `T'


The problem seems related to the generics' constraints and derived interfaces.

The current class definition is the following:

public class MatrixArray<T> : List<T> where T : IMatrix

Please Note that if I change the constraint which says that T must
implement interface IMatrix to saying T must implement  the parent of
IMatrix, IMatrixBase, everything works.


Should I file a bug, or the problem is already known?
Thanks,
Matteo


// MatrixArray.cs
using System;
using System.Collections.Generic;

namespace test
{

public class program
{
  static void Main(string[] args)
  {

  }
}


 public interface IMatrixBase
 {
        double this[int r, int c]
        {
            get;
            set;
        }
 }

 public interface IMatrix: IMatrixBase
 {
 }




public class MatrixArray<T> : List<T> where T : IMatrix
{
   public double this[int i1,int i2,int i3]
        {
            get
            {
                return this[i1][i2, i3];
            }
            set
            {
                this[i1][i2, i3] = value;
            }
        }
}

}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MatrixArray.cs
Type: application/octet-stream
Size: 695 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100616/5982332a/attachment.obj 


More information about the Mono-devel-list mailing list