Try to be smarter about when bouncing initialization.

This commit is contained in:
Juraj Kirchheim
2020-01-06 14:35:26 +01:00
parent b48b300cbc
commit a101378a4c

View File

@@ -98,10 +98,36 @@ class Constructor {
var tmp = MacroApi.tempName();
var member = owner.memberByName(name).sure();
var metaBypass = false;
var bypass = switch options.bypass {
case null:
switch member.kind {
case FProp(_, 'default' | 'null', _):
false;
#if haxe4
case FProp('default', 'never', _):
member.isFinal = true;
case FProp(_, 'set', _):
member.addMeta(':isVar');
metaBypass = true;
#end
case FProp(_):
true;
case FFun(_):
pos.error('cannot rebind function');
default: false;
}
case v: v;
}
if (options.bypass && member.kind.match(FProp(_, 'never' | 'set', _, _))) {
member.addMeta(':isVar');
switch member.kind {
case FProp(get, set, _):
member.pos.warning('$get,$set');
default:
}
addStatement((function () {
var fields = [for (f in (macro this).typeof().sure().getClass().fields.get()) f.name => f];
@@ -141,7 +167,13 @@ class Constructor {
}).bounce(), options.prepend);
}
else
addStatement(macro @:pos(pos) this.$name = $e, options.prepend);
addStatement(
if (metaBypass)
macro @:pos(pos) @:bypassAccessor this.$name = $e
else
macro @:pos(pos) this.$name = $e,
options.prepend
);
}
public inline function publish()
if (isPublic == null)