-
-
Notifications
You must be signed in to change notification settings - Fork 658
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
[macro] structure extension information is not available after typing #3198
Comments
Suggestion : store it in some metadata ? |
Or more exactly : let the compiler store it into some metadata that you can later retreive |
Yeah that's one option as I said. I'll try to implement it. |
Oh wait, but |
Maybe create a new TType to that tanon then? |
Meh, i don't know, this is not really a typedef and people may rely on it being plain TAnonymous in their macros. |
Ah right. We could have it into the a_status then |
@ncannasse do you think it will make sense to just add |
something like this nadako@21a20fd |
or is it better to actually have some special a_status for that? i still don't really understand the whole open/closed/const anon status stuff |
Maybe this helps: typedef X = {
x: Int
}
typedef Xy = {
x: Int,
y: String
}
class Main {
static function main() { }
static function opened(a) {
// a is a monomorph here
// field access turns it into an open anon
a.x = 12;
a.y = "foo";
// note the +
$type(a); // {+ y : String, x : Int }
// unify with closed anon Xy
var a2:Xy = a;
// a is closed now
$type(a); // { y : String, x : Int }
// cannot add any more fields
a.z = true;
// can assign to less specific anon
var a3:X = a;
}
static function const() {
var a = { x: 12, y: "foo" };
// a is const here, prints the same
$type(a); // { y : String, x : Int }
// unifies with closed, remains const
var a2:Xy = a;
// does not unify with less specific anon
var a3:X = a;
}
} Open and closed status is quite straightforward: Open anons are only relevant when accessing fields on monomorphs. They allow additional fields to be added. Upon unification they are closed, which means they do not accept any more fields. Const status is more peculiar and I can never remember why it exists in the first place, although it always makes sense when Nicolas explains it (again). It is relevant when working with structure declarations and as far as I can tell the distinguishing feature is that they do not unify with less specific anon types. For your case I'd say the new status should be treated just ilke Closed. |
Am I right thinking that extension info is only relevant for the So what should we do? Here's an implementation with an extra tanon field: nadako/haxe@21a20fd |
any comments?:) |
Add a new case for a_status, that's the best solution |
…onStatus.AExtend (closes HaxeFoundation#3198)
…onStatus.AExtend (closes HaxeFoundation#3198)
Okay, I've added a pull request #3228 adding new anon_status variant. Please review and merge! |
…onStatus.AExtend (closes HaxeFoundation#3198)
store structure extended types and expose it to the macro api with AnonStatus.AExtend (closes #3198)
Typer currently seems to generate a new
TAnonymous
for aTExtend
, merging its fields and losing information about extended types. However, I find that info useful sometimes and would love to see it available somehow (maybe as metadata or AnonStatus param). For example:In our game we have type definitions for game content JSON structures like that:
What I want to do is macro-generate some C# classes for the Unity3D client that wraps those structures and I want to preserve inheritance hierarchy for those classes:
The text was updated successfully, but these errors were encountered: