[nem-bug] [Nemerle 0000657]: Unhandled Exception: Nemerle.Core.MatchFailureException in ncc

feedback at nemerle.org feedback at nemerle.org
Fri Apr 28 13:41:35 CEST 2006


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=657> 
======================================================================
Reported By:                VladD2
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   657
Category:                   Compiler
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
======================================================================
Date Submitted:             04-17-2006 04:09 CEST
Last Modified:              04-28-2006 13:41 CEST
======================================================================
Summary:                    Unhandled Exception:
Nemerle.Core.MatchFailureException in ncc
Description: 
using System.Console;

def Sort[T](lst, gt)
{
  match (lst)
  { | [] => [] : list[T] // This cause of Unhandled Exception
    | head :: tail => Sort($[y | y in tail, gt(head, y)], gt) 
                    + [head]
                    + Sort($[y | y in tail, gt(y, head)], gt)
  }
}

WriteLine(Sort([9, 1, 2, 8, 3, 7, 4, 6, 5, 0], _ > _));
WriteLine(Sort(["B", "A", "Q", "Z", "T", "Z", "J", "C", "D", "H"],
  fun(x, y) { string.Compare(x, y) > 0 }));

If try to compile this code the result compiler crash:
Unhandled Exception: Nemerle.Core.MatchFailureException: Exception of type
'Nemerle.Core.MatchFailureException' was thrown.
   at _N_AutoModule._N_Sort1746[T](_N_closure1740 _N_Main_cp1745, list`1
lst, Function`3 gt) in C:\VS\Nemerle\Tests\Sort.n:line 5
   at _N_AutoModule._N_Sort1746[T](_N_closure1740 _N_Main_cp1745, list`1
lst, Function`3 gt) in C:\VS\Nemerle\Tests\Sort.n:line 7
   at _N_AutoModule.Main() in C:\VS\Nemerle\Tests\Sort.n:line 13
======================================================================

----------------------------------------------------------------------
 malekith - 04-28-06 00:56 
----------------------------------------------------------------------
Mono stack trace shows the cause better:

Unhandled Exception: Nemerle.Core.MatchFailureException: Exception of type
Nemerle.Core.MatchFailureException was thrown.
in <0x008a6> _N_AutoModule:_N_Sort1625[Object] (._N_closure1619
_N_Main_cp1624, Nemerle.Core.list`1 lst, Nemerle.Builtins.Function`3 gt)
in <0x00474> _N_AutoModule:_N_Sort1625[Int32] (._N_closure1619
_N_Main_cp1624, Nemerle.Core.list`1 lst, Nemerle.Builtins.Function`3 gt)
in <0x00194> _N_AutoModule:Main ()
    0.05s real     0.04s user     0.01s system
Non zero exit code.

we're calling Sort[object] from Sort[int], which is wrong. I'm not sure
why though. Will investigate.

The fully typed version:
  def Sort[T](lst:list[T], gt)
works fine (just in case you need this to work now).

----------------------------------------------------------------------
 VladD2 - 04-28-06 12:26 
----------------------------------------------------------------------
I understand that it's wrong code.

But compiler should report correct error message but not crash.

----------------------------------------------------------------------
 malekith - 04-28-06 13:41 
----------------------------------------------------------------------
The code is OK. Note that it's the generated code what is wrong, not the
source.

It is OK, because by enforcing result type to be list[T], you also enforce
the source type to be list[T] (because you're using + on result type and
source type).

Issue History
Date Modified  Username       Field                    Change              
======================================================================
04-17-06 04:09 VladD2         New Issue                                    
04-28-06 00:56 malekith       Note Added: 0001205                          
04-28-06 12:26 VladD2         Note Added: 0001206                          
04-28-06 13:41 malekith       Note Added: 0001207                          
======================================================================




More information about the bugs mailing list