Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeDefinitions generated in OnTypeNotFound handler don"t respect empty package. #11322

Open
0b1kn00b opened this issue Oct 3, 2023 · 2 comments

Comments

@0b1kn00b
Copy link

0b1kn00b commented Oct 3, 2023

OnTypeNotFoundPackageIssue.zip

Haxe 4.3.1

The following induces TypeNotFound to look for pack.String.

src/Plugin.hx:3: use plugin
src/GenerateTypeDefinition.hx:11: pack.TypeNotExist
src/GenerateTypeDefinition.hx:13: ok
src/GenerateTypeDefinition.hx:32: package pack;
class TypeNotExist {
        function react() {
                final t:String = "hello";
        }
}
src/GenerateTypeDefinition.hx:11: pack.String
src/GenerateTypeDefinition.hx:11: pack.StdTypes
public function apply(type_name):Null<TypeDefinition>{
    trace(type_name);
    return if(type_name == "pack.TypeNotExist"){
      trace("ok");
      final expr = macro {final t:String = "hello";};
      final f : Function    = {
        args : [],
        ret  : null,
        expr : expr
      }
      final field : Field = {
        name  : "react",
        pos   : Context.currentPos(),
        kind  : FFun(f), 
      }
      final tdef : TypeDefinition = {
        pack  : ["pack"],
        name  : "TypeNotExist",
        pos   : Context.currentPos(),
        kind : TDClass(),
        fields : [field]
      };
      trace(new haxe.macro.Printer().printTypeDefinition(tdef));
      tdef;
    }else{
      null;
    }
@0b1kn00b 0b1kn00b changed the title TypeDefinitions generated in OnTypeNotFound handler don"t capture root package TypeDefinitions generated in OnTypeNotFound handler don"t respect empty package. Oct 3, 2023
@filt3rek
Copy link
Contributor

filt3rek commented Oct 3, 2023

Hej,

You can access "root" package using "std" like that : final expr = macro {final t:std.String = "hello";};
But I agree it"s not very handy

@0b1kn00b
Copy link
Author

0b1kn00b commented Oct 3, 2023

If you pull say a std.String declaration from a field, the std package is already elided I think .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants