@@ -62,6 +62,7 @@ private enum Phase { LIGHT, HEAVY }
6262 private final Map <ClassDef , Map <GlobalVarDef , Integer >> classVarInitOrderCache = new HashMap <>();
6363 private final Map <GlobalVarDef , Boolean > guaranteedClassFieldInitCache = new IdentityHashMap <>();
6464 private final Map <GlobalVarDef , List <GlobalVarDef >> moduleFieldCopiesCache = new IdentityHashMap <>();
65+ private boolean moduleFieldCopiesIndexed ;
6566
6667 /**
6768 * When true, the build targets a legacy patch (pre-1.24) whose Blizzard-provided
@@ -87,6 +88,7 @@ public void validate(Collection<CompilationUnit> toCheck) {
8788 heavyBlocks .clear ();
8889 guaranteedClassFieldInitCache .clear ();
8990 moduleFieldCopiesCache .clear ();
91+ moduleFieldCopiesIndexed = false ;
9092
9193 lightValidation (toCheck );
9294
@@ -1988,11 +1990,12 @@ private boolean constructorAssignsField(ConstructorDef constructor, GlobalVarDef
19881990 return true ;
19891991 }
19901992 FunctionCall thisCall = getFirstThisConstructorCall (constructor );
1991- if (thisCall == null ) {
1992- return false ;
1993+ if (thisCall != null ) {
1994+ ConstructorDef target = OverloadingResolver .resolveThisCall (constructorsFor (constructor ), thisCall );
1995+ return target != null && target != constructor && constructorAssignsField (target , field , visiting );
19931996 }
1994- ConstructorDef target = OverloadingResolver . resolveThisCall ( constructorsFor ( constructor ), thisCall );
1995- return target != null && target != constructor && constructorAssignsField (target , field , visiting );
1997+ ConstructorDef superConstructor = constructor . attrSuperConstructor ( );
1998+ return superConstructor != null && constructorAssignsField (superConstructor , field , visiting );
19961999 }
19972000
19982001 private List <ConstructorDef > constructorsFor (GlobalVarDef field ) {
@@ -2035,36 +2038,32 @@ private List<ConstructorDef> enclosingClassConstructors(GlobalVarDef field) {
20352038 }
20362039
20372040 private List <GlobalVarDef > moduleFieldCopies (GlobalVarDef field ) {
2038- List <GlobalVarDef > cached = moduleFieldCopiesCache .get (field );
2039- if (cached != null ) {
2040- return cached ;
2041- }
2042- ClassOrModule owner = field .attrNearestClassOrModule ();
2043- if (!(owner instanceof ModuleDef module )) {
2044- cached = Collections .emptyList ();
2045- moduleFieldCopiesCache .put (field , cached );
2046- return cached ;
2041+ if (!moduleFieldCopiesIndexed ) {
2042+ indexModuleFieldCopies ();
20472043 }
2048- int fieldIndex = module .getVars ().indexOf (field );
2049- if (fieldIndex < 0 ) {
2050- cached = Collections .emptyList ();
2051- moduleFieldCopiesCache .put (field , cached );
2052- return cached ;
2044+ return moduleFieldCopiesCache .getOrDefault (field , Collections .emptyList ());
2045+ }
2046+
2047+ private void indexModuleFieldCopies () {
2048+ if (moduleFieldCopiesIndexed ) {
2049+ return ;
20532050 }
2054- List <GlobalVarDef > copies = new ArrayList <>();
20552051 prog .accept (new Element .DefaultVisitor () {
20562052 @ Override
20572053 public void visit (ModuleInstanciation instantiation ) {
2058- if (instantiation .attrModuleOrigin () == module
2059- && fieldIndex < instantiation .getVars ().size ()) {
2060- copies .add (instantiation .getVars ().get (fieldIndex ));
2054+ ModuleDef origin = instantiation .attrModuleOrigin ();
2055+ if (origin != null ) {
2056+ int count = Math .min (origin .getVars ().size (), instantiation .getVars ().size ());
2057+ for (int i = 0 ; i < count ; i ++) {
2058+ GlobalVarDef originField = origin .getVars ().get (i );
2059+ moduleFieldCopiesCache .computeIfAbsent (originField , ignored -> new ArrayList <>())
2060+ .add (instantiation .getVars ().get (i ));
2061+ }
20612062 }
20622063 super .visit (instantiation );
20632064 }
20642065 });
2065- cached = List .copyOf (copies );
2066- moduleFieldCopiesCache .put (field , cached );
2067- return cached ;
2066+ moduleFieldCopiesIndexed = true ;
20682067 }
20692068
20702069 private boolean initializedBySuperConstructor (ConstructorDef constructor , GlobalVarDef field ) {
0 commit comments