[nem-bug] [Nemerle 0000625]: strange error when misusing
macro-generated type
feedback at nemerle.org
feedback at nemerle.org
Mon May 1 12:50:31 CEST 2006
The following issue has been RESOLVED.
======================================================================
<http://nemerle.org/bugs/view.php?id=625>
======================================================================
Reported By: aleksey
Assigned To: nazgul
======================================================================
Project: Nemerle
Issue ID: 625
Category: Compiler
Reproducibility: always
Severity: minor
Priority: normal
Status: resolved
Resolution: fixed
Fixed in Version:
======================================================================
Date Submitted: 02-22-2006 10:40 CET
Last Modified: 05-01-2006 12:50 CEST
======================================================================
Summary: strange error when misusing macro-generated type
Description:
When someone misuses(e.g. uses non-existent function or property accessor)
a type defined from macro, he gets a quite strange error message.
E.g. lets suppose we have a macro 'define', which defines type with a
supplied name, etc.
define(Test);
def t = Test(1);
// there is no 'Prop' property in Test
System.Console.WriteLine(t.Prop);
The following error message is displayed:
c.n:1:1:1:7: you must specify `partial' modifier on all declarations of
type `Test'
c.n:1:1:1:7: first defined here
c.n:1:1:1:7: field `Test.test' redefined in `Test'
c.n:1:1:1:7: first definition here as field `Test.test'
confused by earlier errors bailing out
======================================================================
----------------------------------------------------------------------
nazgul - 02-22-06 11:13
----------------------------------------------------------------------
Looks like the type is added twice to the compilation tree. I'm not sury
why though. Did you check the examples from
ncc/testsuite/positive/macrolib.n and macroprog.n?
----------------------------------------------------------------------
aleksey - 02-22-06 12:51
----------------------------------------------------------------------
Here's how to reproduce this error via macro from macrolib.n:
def x = generateIFoo();
_ = x.Test;
----------------------------------------------------------------------
steffen - 02-22-06 15:20
----------------------------------------------------------------------
The problem is that the macro is called twice when an error occurs:
macrolib.n:
macro M () {
System.Console.WriteLine ("Macro called");
Nemerle.Macros.ImplicitCTX ().Env.Define
(<[ decl:
public class BlahBle { }
]>).Compile ();
<[ () ]>
}
If you compile the code:
M();
the compiler will output:
Macro called
and the compilation will work.
If you, however, try to compile
M();
asdf();
the compiler will output:
Macro called
Macro called
test.n:1:1:1:2: error: you must specify `partial' modifier on all
declarations of type `BlahBle'
test.n:1:1:1:2: error: first defined here
confused by earlier errors bailing out
I don't know exactly why the compiler evaluates the macro twice in case of
an error. (He seems to restart in some error mode.) This behaviour doesn't
matter as long as the macro is pure functional (which in most cases is
true).
However, to solve this problem you either have to check, that the type is
created only once, even when the macro is evaluated twice, or the compiler
has to stop evaluting macros twice in case of an error (but I don't know
whether that is possible.)
----------------------------------------------------------------------
malekith - 02-22-06 15:31
----------------------------------------------------------------------
You're right, we do restarts in error mode.
It would be hard to prevent the compiler from executing macros in such
situation, because for example the error can be in the code produced by
the macro. Nevertheless it shouldn't be hard to add a special property to
ImplicitCTX() to check if we're running in the error mode (presumably for
the second time).
----------------------------------------------------------------------
nazgul - 05-01-06 12:50
----------------------------------------------------------------------
I added the new property in Typer, it is now described in
http://nemerle.org/Defining_types_from_inside_macros
Issue History
Date Modified Username Field Change
======================================================================
02-22-06 10:40 aleksey New Issue
02-22-06 11:13 nazgul Note Added: 0001100
02-22-06 12:51 aleksey Note Added: 0001101
02-22-06 15:20 steffen Note Added: 0001103
02-22-06 15:31 malekith Note Added: 0001104
02-22-06 21:16 VladD2 Issue Monitored: VladD2
05-01-06 12:50 nazgul Status new => resolved
05-01-06 12:50 nazgul Resolution open => fixed
05-01-06 12:50 nazgul Assigned To => nazgul
05-01-06 12:50 nazgul Note Added: 0001216
======================================================================
More information about the bugs
mailing list