[nem-bug] [Nemerle 0000639]: A compile-time calculus and code generation

feedback at nemerle.org feedback at nemerle.org
Tue Mar 28 21:39:57 CEST 2006


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=639> 
======================================================================
Reported By:                VladD2
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   639
Category:                   Compiler
Reproducibility:            always
Severity:                   crash
Priority:                   normal
Status:                     new
======================================================================
Date Submitted:             03-28-2006 02:27 CEST
Last Modified:              03-28-2006 21:39 CEST
======================================================================
Summary:                    A compile-time calculus and code generation
Description: 
If write macro like this:
using System;

macro CompileTimeFactorial(x : uint)
{
  def factorial = Math.Factorial(x);
  <[ $(factorial : ulong) ]>
}

public module Math
{
  public static Factorial(x : uint) : ulong
  {
    def Loop(acc : ulong, x : uint)
    {
      if (x <= 1) acc else Loop(acc * x, x - 1)
    };
    
    Loop (1UL, x)
  }
}

and try to use it like this:
WriteLine(CompileTimeFactorial(0));

The compiler generate such IL:
.method private hidebysig static void Main() cil managed
{
      .entrypoint
      .maxstack 1
      L_0000: ldc.i8 1
      L_0009: conv.u8 
      L_000a: call void [mscorlib]System.Console::WriteLine(int32)
      L_000f: ret 
}

That is in a fanction which take int32 parameter pass uint64 argument.
If run this code AV is expected.
======================================================================

----------------------------------------------------------------------
 nazgul - 03-28-06 21:39 
----------------------------------------------------------------------
This is strange, the literal expression created inside macro is properly
initialized as UInt64 literal. I don't know why overloading engine treat
it as int.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
03-28-06 02:27 VladD2         New Issue                                    
03-28-06 21:39 nazgul         Note Added: 0001127                          
======================================================================




More information about the bugs mailing list