Macros Haxe宏:导致无效的静态访问

Macros Haxe宏:导致无效的静态访问,macros,haxe,Macros,Haxe,我在Haxe中遇到了一些问题,实际上无法解决它。我也找不到任何关于宏的好文档,所以如果你知道一个,如果你能与我分享,我将不胜感激 代码如下: class ProfilesContainerBuilder { #if macro public static function build() : ComplexType { var fields = new Array<Field>(); switch (Context.getLocalType()

我在Haxe中遇到了一些问题,实际上无法解决它。我也找不到任何关于宏的好文档,所以如果你知道一个,如果你能与我分享,我将不胜感激

代码如下:

class ProfilesContainerBuilder {
#if macro
    public static function build() : ComplexType {
        var fields = new Array<Field>();
        switch (Context.getLocalType()) {
            case TInst(_, [t1]):
                fields.push({
                    name: "get",
                    access: [APublic,AStatic],
                    pos: Context.currentPos(),
                    kind: FieldType.FVar(Context.getLocalType().toComplexType(),null)
                });
                fields.push({
                    name: "profile",
                    access: [APublic,AStatic],
                    pos: Context.currentPos(),
                    kind: FieldType.FVar(t1.toComplexType(),null)
                });
                fields.push({
                    name: "_getProfile",
                    access: [],
                    pos: Context.currentPos(),
                    kind: FieldType.FFun({
                        args: [],
                        expr: { pos: Context.currentPos(), expr: EReturn(
                            macro $i{t1.getClass().name+'.fromDynamic(Json.parse(Assets.getText("profiles/"+_activeProfile+".json")))'} )},
                        params: [],
                        ret: t1.toComplexType()
                    })
                });
            default:
                Context.error("Class expected", Context.currentPos());
        }
        return TAnonymous(fields);
    }
#end
}
类档案ContainerBuilder{
#如果宏
公共静态函数build():ComplexType{
变量字段=新数组();
开关(Context.getLocalType()){
箱锡(t1]):
推({
名称:“获取”,
访问:[公共,无状态],
pos:Context.currentPos(),
种类:FieldType.FVar(Context.getLocalType().toComplexType(),null)
});
推({
名称:“个人资料”,
访问:[公共,无状态],
pos:Context.currentPos(),
种类:FieldType.FVar(t1.toComplexType(),null)
});
推({
名称:“_getProfile”,
访问权限:[],
pos:Context.currentPos(),
种类:FieldType.FFun({
args:[],
expr:{pos:Context.currentPos(),expr:EReturn(
宏$i{t1.getClass().name+'.fromDynamic(Json.parse(Assets.getText(“profiles/”+_-activeProfile+“.Json”)))')},
参数:[],
ret:t1.toComplexType()
})
});
违约:
错误(“应为类”,Context.currentPos());
}
返回TAnonymous(字段);
}
#结束
}
@:remove@:genericBuild(brocchinia.io.ressource.ProfilesContainerBuilder.build())
外部接口配置文件容器{}
然后,在实现构建接口的类中,出现了给定的错误:

C:/HaxeToolkit/haxe/lib/brocchinia/0,1,0/brocchinia/io/ressource/ressource.hx:27:第27-114行:无效静态访问

知道我从静态和本地函数访问变量get、profile和函数
\u getProfile
。没有宏部分,它工作得很好


经过数小时的研究,我还没有发现问题,因此感谢您的关注。

我发现了问题,我误解了
通用构建的工作原理,感谢所有阅读过的人

实际上,代码在类型
T
上执行一个函数,这是不可能的,这就是抛出错误的原因

@:remove @:genericBuild(brocchinia.io.ressource.ProfilesContainerBuilder.build())
extern interface ProfilesContainer<T> { }