rsdn / nemerle

Nemerle language. Main repository.
http://nemerle.org
Other
618 stars 89 forks source link

[ICE] Cannot create type alias with compile-time generated name from macros #529

Open pekabon opened 11 years ago

pekabon commented 11 years ago

this code compile successfully:


def b = "int";
def builder = typer.Env.Define(<[decl: type myuint = $(b : dyn);]>);
builder.Compile();

this one doesn't:


def a = "myuint";
def b = "int";

def builder = typer.Env.Define(<[decl: type $(a : dyn) = $(b : dyn);]>);
builder.Compile();

output error : parse error near operator $': expecting=', ;' or{' in field / property declaration error : parse error near operator `$': unexpected token after class member (you forget a closing bracket?).

trying workaround, this compiles and works:


def b = "int";

def typePExpr = <[$(b : dyn)]>;
def name = Splicable.Name(<[myuint]>);

def topDeclaration = TopDeclaration.Alias(name,  AttributesAndModifiers(), Typarms.Empty, typePExpr);
def typeDeclaration = ClassMember.TypeDeclaration(name, topDeclaration);

def builder = typer.Env.Define(typeDeclaration);
builder.Compile();

but this code doesn't (ICE):


def a = "myuint";
def b = "int";

def typePExpr = <[$(b : dyn)]>;
def name = Splicable.Name(<[$(a : dyn)]>);

def topDeclaration = TopDeclaration.Alias(name,  AttributesAndModifiers(), Typarms.Empty, typePExpr);
def typeDeclaration = ClassMember.TypeDeclaration(name, topDeclaration);

def builder = typer.Env.Define(typeDeclaration);
builder.Compile();
error : Internal compiler error 'env is null for myuint', please report a bug to bugs.nemerle.org. You can try modifying program near this location.
C:\Program Files (x86)\Nemerle\Net-4.0\Nemerle.MSBuild.targets(289,5): error : internal compiler error: assertion failed in file ncc\hierarchy\TypeBuilder.n, line 145: env is null for myuint
       в Nemerle.Compiler.TypeBuilder..ctor(TypesManager manager, TypeBuilder par, TopDeclaration td, Node ns_node)
       в Nemerle.Compiler.NamespaceTree.AddType(TypeBuilder par, Node parent_node, TopDeclaration newdecl)
       в Nemerle.Compiler.GlobalEnv.Define(ClassMember td, Boolean do_fixup)
       в MacroLibrary1.Macro1Impl.DoTransform(Typer typer) в I:\Sources\Miniprojects\MacroLibrary1\MacroLibrary1\Macro1.n:строка 51
       в MacroLibrary1._N_operator1116474_4357Macro.Run(Typer _N__1, list`1 parms) в I:\Sources\Miniprojects\MacroLibrary1\MacroLibrary1\Macro1.n:строка 29
       в Nemerle.Compiler.TypesManager.AttributeMacroExpansion.Expand()
       в Nemerle.Compiler.TypesManager.ExpandMacros()
       в Nemerle.Compiler.TypesManager.Run()
       в Nemerle.Compiler.ManagerClass.Run()
       в Nemerle.CommandlineCompiler.MainClass.main_with_catching()
NN--- commented 11 years ago

Seems compiler doesn't support quotes for type statement. You can use <[ type x = $(m : usesite) ]> , rather than 'dyn'.

pekabon commented 11 years ago

<[ type x = $(m : usesite) ]> is not my case, I want <[ type $(x : usesite) = $(m : usesite) ]> (doesn't compile)

but now I have workaround, thanx:

def a = "myuint";
def b = "int";
def typePExpr = <[$(b : usesite]>;
def name = Splicable.Name(<[$(a : usesite)]>);
def topDeclaration = TopDeclaration.Alias(name,  AttributesAndModifiers(), Typarms.Empty, typePExpr);
def typeDeclaration = ClassMember.TypeDeclaration(name, topDeclaration);

def builder = typer.Env.Define(typeDeclaration);
builder.Compile();
NN--- commented 11 years ago

The problem that compiler doesn't support this kind of quote , you can teach compiler to support it :)