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 @@ -1780,7 +1780,8 @@ private void checkField(NameRef access) {
17801780 if (!(field .getInitialExpr () instanceof NoExpr )
17811781 || (isCurrentInstanceAccess (access )
17821782 && writtenFields .contains (field ))
1783- || (!(function instanceof ConstructorDef ) && hasGuaranteedConstructorAssignment (field ))
1783+ || ((!isCurrentInstanceAccess (access ) || !(function instanceof ConstructorDef ))
1784+ && hasGuaranteedConstructorAssignment (field ))
17841785 || (delegatedConstructorCall != null && !access .isSubtreeOf (delegatedConstructorCall )
17851786 && hasGuaranteedConstructorAssignment (field ))
17861787 || !warned .add (field )) {
Original file line number Diff line number Diff line change @@ -278,6 +278,27 @@ public void doesNotWarnForExplicitReceiverWithGuaranteedConstructorAssignment()
278278 result .getGui ().getWarningList ().toString ());
279279 }
280280
281+ @ Test
282+ public void doesNotWarnForInitializedExplicitReceiverInsideConstructor () {
283+ CompilationResult result = test ()
284+ .setStopOnFirstError (false )
285+ .executeProg (false )
286+ .lines (
287+ "package Test" ,
288+ "class Source" ,
289+ " int value" ,
290+ " construct()" ,
291+ " value = 1" ,
292+ "class Holder" ,
293+ " construct(Source source)" ,
294+ " int copy = source.value"
295+ );
296+
297+ assertFalse (result .getGui ().getWarningList ().stream ()
298+ .anyMatch (w -> w .getMessage ().contains ("no explicit initializer and is not definitely assigned" )),
299+ result .getGui ().getWarningList ().toString ());
300+ }
301+
281302 @ Test
282303 public void warnsForUninitializedFieldReadFromPackageFunction () {
283304 test ()
You can’t perform that action at this time.
0 commit comments