elnabo / json2object

Type safe Haxe/JSON (de)serializer
MIT License
66 stars 17 forks source link

DataBuilder error "Type name JsonParser_1 is redefined from module JsonParser_1" once in a while #74

Closed olichose123 closed 3 years ago

olichose123 commented 3 years ago

I often get this strange compilation bug that nothing can fix but a reload of vscode and I'm not sure why it happens. image

Type name JsonParser_1 is redefined from module JsonParser_1 in json2object\3,9,0\src\json2object\reader at line 396.

So far any simple use of json2object will generate this error in any single project. The fact that I could not find a similar issue and that a restart of vscode might indicate that it is caused by the compilation of hl and not json2object itself, but others might have an idea of what it is.

olichose123 commented 3 years ago

Seems to be a compilation problem after all, related to https://github.com/HaxeFoundation/haxe/issues/8368. Not the fault of this lib.

kLabz commented 1 year ago

Hi, can you still reproduce this easily? I'm working on the haxe issue you mentioned, and need a few different reproduction samples.

olichose123 commented 1 year ago

No problem. Will come back with my latest attempt.

olichose123 commented 1 year ago

It looks like I cannot replicate this with Haxe 4.2.5 and json2object 3.10.0. I'm guessing the underlying macro bug has been fixed, or somehow there was a problem with my environment (though I would later discover it used to happen on multiple computers when playing with macros, not only with this lib).

So I'd consider this one fixed/not a problem. I'm really happy that it now works correctly and should have tried it months ago!

Pidroh commented 1 year ago

@kLabz I can reproduce this on haxe 4.2.5 and json2object 3.10.0

It happens when I define a reader and a writer of anonymous structures in two different classes as static variables, separate files. If they are in the same file I think there is no problem, most of the time

Pidroh commented 1 year ago

However, it is unstable and changing related files a bit + recompiling fixes the issue. Sometimes.

kLabz commented 1 year ago

Hi @Pidroh, thanks! Indeed I can reproduce on both 4.2.5 and nightlies.

The issue is not a Haxe compiler issue; DataBuilder is not compiler cache safe. Issue can be dodged by adding @:persistent to DataBuilder's counter.

cc @elnabo

Edit: There's a Haxe compiler generated X is redefined from X issue happening in some cases (while editing DataBuilder) after fixing this, when using a nightly older than https://github.com/HaxeFoundation/haxe/commit/b3b3d6b48a39b2c5a40b0fd137868dd81827e179. More recent nightlies and 4.2.5 are fine.

Pidroh commented 1 year ago

@kLabz Made a pull request, did not test it https://github.com/elnabo/json2object/pull/85

Would that fix the problem?

elnabo commented 1 year ago

The fix should now be available with version 3.11.0 on haxelib.

Pidroh commented 1 year ago

@kLabz Hii, that fix wasn't enough, I still get the error sometimes :(

sometimes I also get Uncaught ReferenceError: JsonParser_$11 is not defined when running the game on the browser (building to Javascript)

Do you think the problem is also happening somewhere else?

RblSb commented 1 year ago

@kLabz do you mean that this @:persistent fix can be #if defined for Haxe <4.3? With this counter increment after every server compilation this is annoying to check diffs of target codes, all types change with JsonParser_$678 stuff.

Also, reproducible example of this bug would be nice to see.