haxetink / tink_macro

The macro toolkit
MIT License
57 stars 17 forks source link

TypeMap can't distinguish anon type with field meta #25

Closed kevinresol closed 4 years ago

kevinresol commented 5 years ago

The following code illustrate the issue:

class Main {
  static function main() {
    var a = tink.Json.parse(('{"a":1}':A));
    trace(a);
    var b = tink.Json.parse(('{"b":1}':B)); // using the same parser as A and fails at runtime
    trace(b);
  }
}

typedef A = {@:json('a') var foo:Int;}
typedef B = {@:json('b') var foo:Int;}
kevinresol commented 5 years ago

Tried to perform some deep comparison but there will be recursion problem for types like:

typedef Rec = {v:Rec}
kevinresol commented 5 years ago

I wonder how the compiler figures out these two types to be the same:

typedef R1 = {x:R1};
typedef R2 = {x:R2};
back2dos commented 4 years ago

Essentially, we can now pass any normalizer to the TypeMap / BuildCache. Still need to figure out what's best for each particular lib though ^^