Metadata on anonymous structures?

38 views
Skip to first unread message

Drakim

unread,
Aug 16, 2016, 8:24:21 AM8/16/16
to Haxe
Is it possible to put metadata on an anonymous structure, akin to how you can while using a typedef structure?

I can do this:
typedef User = {
 
var age : Int;
 
var name : String;
 
@test(3) var phoneNumber : String;
}

But I can't do this:
var mything:{
  age
:Int,
  name
:String,
 
@test(3) phoneNumber:String
};

I realize having metadata on such a short-lived structure type doesn't seem very useful, but I'm passing the structure to a macro, and I need to be able to tag some fields as being special to the macro (the alternative would be to do so in the names of the fields so the macro could see).

Dan Korostelev

unread,
Aug 16, 2016, 8:41:21 AM8/16/16
to Haxe
there's no such thing as "typedef structure", a typedef is always just an alias.
but there's two structure notations, the "short" one you used for the var doesn't support metadata, but you can use the same notation as with typedef for the var type as well, e.g.:

var mything:{@test(3) var phoneNumber:String;} = ...

вторник, 16 августа 2016 г., 15:24:21 UTC+3 пользователь Drakim написал:

Drakim

unread,
Aug 16, 2016, 8:53:44 AM8/16/16
to Haxe
That solves the issue for me, thanks a lot Dan!
Reply all
Reply to author
Forward
0 new messages