[nem-bug] [Nemerle 0000814]: Nemerle default indexer not compatibility with C#

feedback at nemerle.org feedback at nemerle.org
Thu Dec 28 17:35:17 CET 2006


The following issue has been ASSIGNED.
======================================================================
<http://nemerle.org/bugs/view.php?id=814> 
======================================================================
Reported By:                VladD2
Assigned To:                nazgul
======================================================================
Project:                    Nemerle
Issue ID:                   814
Category:                   Compiler
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     assigned
======================================================================
Date Submitted:             12-27-2006 05:06 CET
Last Modified:              12-28-2006 17:35 CET
======================================================================
Summary:                    Nemerle default indexer not compatibility with C#
Description: 
If create in Nemerle assembly which containe type with default accessor:
public Item[fileIndex : int] : SomeType
{
  get
  {
    ...
  }
}
and try use it from C# application you get error:
error CS0570: 'Nemerle.Completion2.CompileUnitCollection.this[int]' is not
supported by the language

======================================================================

----------------------------------------------------------------------
 malekith - 12-27-06 09:59 
----------------------------------------------------------------------
It works for me. Moreover the generated IL seems to be *exactly* the same
as in C# (using gmcs). Could you provide a self-contained example?

----------------------------------------------------------------------
 VladD2 - 12-27-06 14:32 
----------------------------------------------------------------------
Please, see rev. 7158. 
The indexer for CompileUnits defined in
Nemerle.VSIP\Nemerle.Compiler.Utils\Nemerle.Completion2\CodeModel\CompileUnitCollection.n
(line 40).

----------------------------------------------------------------------
 nazgul - 12-27-06 23:59 
----------------------------------------------------------------------
public class X {
    public Item [x : int] : string { get { x.ToString () } }
    public Item [x : string] : string { get { x } }
}


Looks like we emit two DefaultMember attributes instead of one.

----------------------------------------------------------------------
 VladD2 - 12-28-06 00:07 
----------------------------------------------------------------------
Hm... May be.
I create some test in C#:
------------------------------------------------------------------
using System;

class A
{
	public int this[int i] { get { return i; } }
	public int this[string s] { get { return s.GetHashCode(); } }

	static void Main()
	{
		A a = new A();
		Console.WriteLine(a[1]);
		Console.WriteLine(a["1"]);
	}
}
------------------------------------------------------------------
csc.exe produce for it following MSIL (from Reflector):
------------------------------------------------------------------
.class private auto ansi beforefieldinit A
      extends object
{
      .custom instance void
[mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = (
string("Item") )
      .method public hidebysig specialname rtspecialname instance void
.ctor() cil managed
      {
      }

      .method private hidebysig static void Main() cil managed
      {
            .entrypoint
      }


      .property int32 Item
      {
            .get instance int32 A::get_Item(string)
      }

      .property int32 Item
      {
            .get instance int32 A::get_Item(int32)
      }
}
------------------------------------------------------------------

----------------------------------------------------------------------
 VladD2 - 12-28-06 00:15 
----------------------------------------------------------------------
Same test on ncc:
------------------------------------------------------------------
using System.Console;

class A
{
  public Item[i : int] : int { get { i } }
  public Item[s : string] : int { get { s.GetHashCode() } }
  static Main() : void
  {
    def a = A();
    WriteLine(a[1]);
    WriteLine(a["1"]);
  }
}
------------------------------------------------------------------
.class private auto ansi beforefieldinit A
      extends object
{
      .custom instance void
[mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = (
string("Item") )
      .custom instance void
[mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = (
string("Item") )
      .method public hidebysig specialname rtspecialname instance void
.ctor() cil managed
      {
      }

      .method private hidebysig static void Main() cil managed
      {
            .entrypoint
      }


      .property [Nemerle]Nemerle.Builtins.Function`2<int32, int32> Item
      {
            .get instance int32 A::get_Item(int32)
      }

      .property [Nemerle]Nemerle.Builtins.Function`2<string, int32> Item
      {
            .get instance int32 A::get_Item(string)
      }
}
------------------------------------------------------------------
Also pay attention on the return type of properties!

Issue History
Date Modified  Username       Field                    Change              
======================================================================
12-27-06 05:06 VladD2         New Issue                                    
12-27-06 09:59 malekith       Note Added: 0001588                          
12-27-06 09:59 malekith       Status                   new => feedback     
12-27-06 09:59 malekith       Description Updated                          
12-27-06 14:32 VladD2         Note Added: 0001589                          
12-27-06 23:59 nazgul         Note Added: 0001591                          
12-27-06 23:59 nazgul         Status                   feedback => confirmed
12-27-06 23:59 nazgul         Description Updated                          
12-28-06 00:07 VladD2         Note Added: 0001592                          
12-28-06 00:15 VladD2         Note Added: 0001593                          
12-28-06 17:35 nazgul         Status                   confirmed => assigned
12-28-06 17:35 nazgul         Assigned To               => nazgul          
======================================================================




More information about the bugs mailing list