File tree Expand file tree Collapse file tree
main/java/de/peeeq/wurstscript/validation
test/java/tests/wurstscript/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2008,6 +2008,7 @@ private void checkField(NameRef access) {
20082008 if (!(nameDef instanceof GlobalVarDef referenced )
20092009 || !referenced .attrIsDynamicClassMember ()
20102010 || !(referenced .getInitialExpr () instanceof NoExpr )
2011+ || (!isCurrentInstanceAccess (access ) && hasGuaranteedConstructorAssignment (referenced ))
20112012 || !warned .add (referenced )) {
20122013 return ;
20132014 }
Original file line number Diff line number Diff line change @@ -257,6 +257,27 @@ public void doesNotTreatDeferredClosureInitializerAsImmediateFieldRead() {
257257 result .getGui ().getWarningList ().toString ());
258258 }
259259
260+ @ Test
261+ public void doesNotWarnForExplicitReceiverWithGuaranteedConstructorAssignment () {
262+ CompilationResult result = test ()
263+ .setStopOnFirstError (false )
264+ .executeProg (false )
265+ .lines (
266+ "package Test" ,
267+ "class Source" ,
268+ " int value" ,
269+ " construct()" ,
270+ " value = 1" ,
271+ "class Holder" ,
272+ " Source source = new Source()" ,
273+ " int copy = source.value"
274+ );
275+
276+ assertFalse (result .getGui ().getWarningList ().stream ()
277+ .anyMatch (w -> w .getMessage ().contains ("read from a field initializer" )),
278+ result .getGui ().getWarningList ().toString ());
279+ }
280+
260281 @ Test
261282 public void classes1 () throws IOException {
262283 testAssertOkFile (new File (TEST_DIR + "Classes_1.wurst" ), true );
You can’t perform that action at this time.
0 commit comments