HaxeFoundation / HaxeFoundation/haxe
Field final access is lost during conversion to ComplexType
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
In macro, using `TypeTools.toComplexType` on anonymous type will lose the information about final fields.
The resulting `ComplexType` field will lack the `AFinal` access.
Observed on latest haxe and originally raised there https://github.com/elnabo/json2object/issues/49
Example:
```haxe
import haxe.macro.Context;
using haxe.macro.ComplexTypeTools;
using haxe.macro.TypeTools;
typedef Data = {
final foo:String;
final bar:{
final foobar:String;
}
}
class Main {
static macro function test () {
var dataType = Context.getType("Data");
switch (dataType) {
case TType(_.get()=>t, _):
switch(t.type) {
case TAnonymous(_.get()=>t):
for (field in t.fields) {
if (field.name == "bar") {
switch (field.type) {
case TAnonymous(_.get()=>t):
trace(t.fields[0]); // isFinal : true
case _:
}
trace(field.type.toComplexType()); // access : []
trace(field.type.toComplexType().toString()); // { var foobar : String }
}
}
default:
}
default:
}
return macro null;
}
static function main() {
test();
}
}
```
Or http://try-haxe.mrcdk.com/#919aC
Contributor guide
Assessment
This issue has not been assessed yet.