[nem-bug] [Nemerle 0000570]: heap crashes when there are two heaps that sort different types

feedback at nemerle.org feedback at nemerle.org
Sun Nov 13 20:36:30 CET 2005


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=570> 
======================================================================
Reported By:                user317
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   570
Category:                   The Standard Library
Reproducibility:            always
Severity:                   crash
Priority:                   normal
Status:                     feedback
======================================================================
Date Submitted:             11-13-2005 02:40 CET
Last Modified:              11-13-2005 20:36 CET
======================================================================
Summary:                    heap crashes when there are two heaps that sort
different types
Description: 
heap crashes with 
Unhandled Exception: System.ArrayTypeMismatchException: Source array type
cannot be assigned to destination array type.
in <0x0002c> Nemerle.Collections.Heap`1[Foo]:is_greater (Int32 , Int32 )
in <0x00073> Nemerle.Collections.Heap`1[Foo]:heapify[IComparable] (Int32
)
in <0x00066> Nemerle.Collections.Heap`1[Bar]:ExtractFirst ()
in <0x00157> _N_AutoModule:Main ()

when two heaps are present in the same program that sort different types.


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

----------------------------------------------------------------------
 user317 - 11-13-05 02:43 
----------------------------------------------------------------------
I think collections of System.Object are a terrible idea in the first
place.  This class should be templated so type safety can be enforced at
compile time.

----------------------------------------------------------------------
 nazgul - 11-13-05 09:02 
----------------------------------------------------------------------
For your testcase I get quite many errors like:

t.n:30:4:30:18: error: in argument http://nemerle.org/bugs/view.php?id=1 (x),
needed a
System.IComparable[System.IComparable[System.IComparable[System.IComparable[...]+]+]+]+,
got Foo: Foo is not a subtype of System.IComparable [simple require]

Recently Heap was changed to require IComparable ['a].

Also, the problem you are describing seems to be pre-generics related, so
it simply disappeared after we switched to 2.0 (that is Nemerle version
0.9.0)

So with the current version following program works just fine:
using Nemerle.Collections;
using Nemerle.IO;
using System;

public class Foo : IComparable [Foo] {
   public mutable Fu : double;
   public this(fu : double) {
      this.Fu = fu;
   }
   public CompareTo(obj : Foo) : int {
      | obj is Foo => if(this.Fu > obj.Fu) 1 else if (this.Fu == obj.Fu) 0
else -1;
      | _ => throw ArgumentException("object is not Foo");
   }
}

public class Bar : IComparable [Bar] {
   public mutable Bu : double;
   public this(bu : double) {
      this.Bu = bu;
   }
   public CompareTo(obj : Bar) : int {
      | obj is Bar => if(this.Bu > obj.Bu) 1 else if (this.Bu == obj.Bu) 0
else -1;
      | _ => throw ArgumentException("object is not Bar");
   }
}
def rand = Random();
def fooheap = Heap(100);
def barheap = Heap(100);
for(mutable ii = 0; ii< 1000; ii++) {
   fooheap.Insert(Foo(rand.NextDouble()));
   barheap.Insert(Bar(rand.NextDouble()));
}
while(fooheap.IsEmpty == false) {
   _ = fooheap.ExtractFirst();
}
while(barheap.IsEmpty == false) {
   _ = barheap.ExtractFirst();
}


----------------------------------------------------------------------
 user317 - 11-13-05 20:36 
----------------------------------------------------------------------
Thanks, works great with 0.9.1.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
11-13-05 02:40 user317        New Issue                                    
11-13-05 02:43 user317        Note Added: 0001018                          
11-13-05 09:02 nazgul         Note Added: 0001019                          
11-13-05 09:02 nazgul         Status                   new => feedback     
11-13-05 09:02 nazgul         Description Updated                          
11-13-05 09:02 nazgul         Additional Information Updated                    
11-13-05 20:36 user317        Note Added: 0001020                          
======================================================================




More information about the bugs mailing list