Пытаюсь сделать простой макрос, который вычислит тип поля и добавит родителя в класс.
Но что-то не работает, выдает NullReferenceException в недрах компилятора.
Может я не правильно делаю ?
Использование:
class A
{
public static a : A;
}
[Inherits(A.a)]
class B { }
Сам макрос:
using Nemerle;
using Nemerle.Collections;
using Nemerle.Compiler;
using Nemerle.Compiler.Parsetree;
namespace MacroLibrary1
{
[MacroUsage(MacroPhase.BeforeInheritance, MacroTargets.Class)]
macro Inherits(typeBuilder : TypeBuilder, variable : PExpr)
{
InheritsImpl.DoTransform(Macros.ImplicitCTX(), typeBuilder, variable)
}
module InheritsImpl
{
public DoTransform(typer : Typer, typeBuilder : TypeBuilder, variable : PExpr) : void
{
Macros.DefineCTX(typer);
def c = typeBuilder.Ast :> TopDeclaration.Class;
def typedVariable = typer.TypeExpr(variable);
when (!typedVariable.ty.IsFree)
Message.Error(variable.Location, "expected expression with inferred type");
c.t_extends ::= PExpr.TypedType(typedVariable.Type.Fix());
}
}