[nem-bug] [Nemerle 0000561]: Compiler internal error when defining nested generic tree

feedback at nemerle.org feedback at nemerle.org
Sun Nov 6 20:22:28 CET 2005


The following issue has been CONFIRMED.
======================================================================
<http://nemerle.org/bugs/view.php?id=561> 
======================================================================
Reported By:                gildur
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   561
Category:                   Compiler
Reproducibility:            always
Severity:                   crash
Priority:                   high
Status:                     confirmed
======================================================================
Date Submitted:             11-06-2005 20:08 CET
Last Modified:              11-06-2005 20:22 CET
======================================================================
Summary:                    Compiler internal error when defining nested generic
tree
Description: 
While trying to compile following code:

-----
using System;

public class Set['a] where 'a : IComparable['a]
{
    private variant Tree['a] where 'a : IComparable['a]
    {
        | Node
        {
            left : Tree['a];
            elem : 'a;
            right : Tree['a];
        }
        | Null

        public Insert(x : 'a) : Tree['a]
        {
            match (this) {
                | Node(l, cur, r) when x.CompareTo(cur) < 0 =>
                    Node(l.Insert(x), cur, r)
                | Node(l, cur, r) when x.CompareTo(cur) > 0 =>
                    Node(l, cur, r.Insert(x))
                | Node(_, _, _) =>
                    throw ArgumentException(
                            "Element already exists in the tree");
                | Null =>
                    Node(Null(), x, Null())
            }
        }
    }

    private mutable storage : Tree['a] = Tree.Null();
    
    public Add(x : 'a) : void
    {
        storage = storage.Insert(x);
    }
}
-----

I got:

error: internal compiler error: got ArgumentException (node already in the
tree)in <0x003b6> Nemerle.Collections.Tree:_N_insert8367[TypeInfo]
(Nemerle.Collections._N_closure8357`1 _N_Insert_cp8366,
Nemerle.Collections.Node`1 tree)
[...]

I'm using version 0.9.1 of the compile from unix binary installer.
======================================================================

----------------------------------------------------------------------
 nazgul - 11-06-05 20:22 
----------------------------------------------------------------------
Of course this is a bug

The generic parameters are inherited by nested types, so you can declare
Tree as having zero generic parameters and it will work fine (this is the
same as in C#). So you example can be rewritten as (there is still ['a]
needed then refering to Tree in Node, but I guess this is another bug):

using System;

public class Set['a] where 'a : IComparable['a]
{
   private variant Tree
   {
       | Node
       {
           left : Tree ['a];
           elem : 'a;
           right : Tree ['a];
       }
       | Null

       public Insert(x : 'a) : Tree
       {
           match (this) {
               | Node(l, cur, r) when x.CompareTo(cur) < 0 =>
                   Node(l.Insert(x), cur, r)
               | Node(l, cur, r) when x.CompareTo(cur) > 0 =>
                   Node(l, cur, r.Insert(x))
               | Node(_, _, _) =>
                   throw ArgumentException(
                           "Element already exists in the tree");
               | Null =>
                   Node(Null(), x, Null())
           }
       }
   }

   private mutable storage : Tree = Tree.Null();

   public Add(x : 'a) : void
   {
       storage = storage.Insert(x);
   }
}



Issue History
Date Modified  Username       Field                    Change              
======================================================================
11-06-05 20:08 gildur         New Issue                                    
11-06-05 20:22 nazgul         Note Added: 0001011                          
11-06-05 20:22 nazgul         Priority                 normal => high      
11-06-05 20:22 nazgul         Status                   new => confirmed    
11-06-05 20:22 nazgul         Description Updated                          
======================================================================




More information about the bugs mailing list