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

feedback at nemerle.org feedback at nemerle.org
Mon Nov 14 23:08:43 CET 2005


The following issue has been RESOLVED.
======================================================================
<http://nemerle.org/bugs/view.php?id=561> 
======================================================================
Reported By:                gildur
Assigned To:                malekith
======================================================================
Project:                    Nemerle
Issue ID:                   561
Category:                   Compiler
Reproducibility:            always
Severity:                   crash
Priority:                   high
Status:                     resolved
Resolution:                 fixed
Fixed in Version:           
======================================================================
Date Submitted:             11-06-2005 20:08 CET
Last Modified:              11-14-2005 23:08 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.
======================================================================
Relationships       ID      Summary
----------------------------------------------------------------------
related to          0000563 Generic parameters are not correctly in...
======================================================================

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

But you should note that 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 your example can be
rewritten as:

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);
   }
}

(there is still ['a] needed when refering to the Tree in Node, but I guess
this is another bug)



----------------------------------------------------------------------
 malekith - 11-14-05 23:08 
----------------------------------------------------------------------
This now triggers an error with a descriptive hint.

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                          
11-06-05 20:23 nazgul         Note Edited: 0001011                         
11-06-05 20:26 nazgul         Note Edited: 0001011                         
11-06-05 20:31 nazgul         Relationship added       related to 0000563  
11-14-05 23:08 malekith       Status                   confirmed => resolved
11-14-05 23:08 malekith       Resolution               open => fixed       
11-14-05 23:08 malekith       Assigned To               => malekith        
11-14-05 23:08 malekith       Note Added: 0001023                          
======================================================================




More information about the bugs mailing list