HaxeFoundation / HaxeFoundation/haxe

Field final access is lost during conversion to ComplexType

Open
#8,067 1 comment 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.