HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.17k stars 654 forks source link

"Field needed by Interface is missing" has unknown position when defining from Context.defineType and then using Context.typeof #11754

Open Speedphoenix opened 2 months ago

Speedphoenix commented 2 months ago

Try haxe: https://try.haxe.org/#15BeB54A

  var pos = Context.currentPos();

  var tfields = (macro class {
    public var bit:Int;
  }).fields;

  var t:TypeDefinition = {
    pos: pos,
    pack: [],
    meta: [{name: ":structInit", pos: pos}],
    name: "TestType",
    kind: TDClass([{pack: [], name: "Test", sub: "TestInterface"},]),
    fields: tfields,
  };
  Context.defineType(t);
  var complex:ComplexType = TPath({pack: [], name: "Macro", sub: "TestType"});

  var type = Context.typeof(macro(null : $complex));

this yields

[ERROR] (unknown position)

   | Field bit2 needed by TestInterface is missing
Simn commented 2 weeks ago

~This should fail in some way because you're trying to define a type that already exists, but the error message isn't ideal.~

I misread that code, let me try again...

Edit: I can't tell what you're actually trying to do. To me it looks like the compiler is correct because your TestType class doesn't define bit2, only bit.

kLabz commented 2 weeks ago

I think the issue here is just the lack of position for the error

Simn commented 2 weeks ago

Ah, I seem to struggle with reading comprehension today... This is indeed a bit silly because we don't necessarily know which type this is about.