-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix empty enum again #16
Conversation
src/tink/json/macros/Macro.hx
Outdated
@@ -91,6 +91,9 @@ class Macro { | |||
} | |||
|
|||
static public function getRepresentation(t:Type, pos:Position) { | |||
|
|||
if(t.match(TMono(_))) return None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to guard infinite loop if something happens to be Unknown<0>
.
For example, it happens when doing tink.Json.stringify(None)
, where the type is Option<Unknown>
The
|
|
Right you are, I was thinking about something like this: class Main {
public static function main() {
var o:Struct = tink.Json.parse('{ "e": "EnumValue" }');
trace(o);
}
}
typedef Struct = {
var e:TestEnum;
}
enum TestEnum {
EnumValue;
} |
I think for now the best thing you can do is this enum TestEnum {
@:json({type:'EnumValue'}) EnumValue;
}
trace(tink.Json.stringify({e:EnumValue})); // {"e":{"type":"EnumValue"}} |
It is because the reader reads all enum values as object, so it always expects a |
How so? You should know whether an enum constructor has arguments or not at compile-time, you know the enum's type after all. Note that I have very little idea how tink_json works internally. :) |
When the type is a Enum, the macro basically generate a piece of code that say: "hey we are expecting a enum, let's read it as an object and get the constructor name from within it". So, the parser will always expect a |
So it only checks the next character, meaning "expect either |
Well, that should work in theory. What I mentioned is the current status quo of the parser. |
Closes #14