@@ -28,12 +28,9 @@ public void warnsWhenClassFieldHasNoInitializerOrConstructorAssignment() {
2828 "package Test" ,
2929 "class Counter" ,
3030 " int value" ,
31- " function get() returns int" ,
32- " return value" ,
33- " function readBeforeSet() returns int" ,
31+ " construct()" ,
3432 " int oldValue = value" ,
35- " value = 42" ,
36- " return oldValue"
33+ " value = 42"
3734 );
3835 }
3936
@@ -70,8 +67,7 @@ public void warnsWhenConstructorOnlyAssignsOtherInstanceField() {
7067 " int value" ,
7168 " construct(Counter other)" ,
7269 " other.value = 1" ,
73- " function get() returns int" ,
74- " return value"
70+ " int _observed = this.value"
7571 );
7672
7773 assertEquals (result .getGui ().getWarningList ().stream ()
@@ -105,8 +101,8 @@ public void warnsWhenUnqualifiedArrayFieldHasNoInitializer() {
105101 "package Test" ,
106102 "class Counter" ,
107103 " int values[2]" ,
108- " function get() returns int " ,
109- " return values[0]"
104+ " construct() " ,
105+ " int first = values[0]"
110106 );
111107 }
112108
@@ -120,14 +116,14 @@ public void warnsWhenFieldIsReadOnRightHandSideBeforeAssignment() {
120116 "package Test" ,
121117 "class Counter" ,
122118 " int value" ,
123- " function increment() returns int " ,
119+ " construct() " ,
124120 " value = value + 1" ,
125- " return value "
121+ " skip "
126122 );
127123 }
128124
129125 @ Test
130- public void warnsWhenOtherInstanceFieldIsReadAfterThisFieldWrite () {
126+ public void warnsWhenOtherInstanceFieldIsReadInConstructor () {
131127 test ()
132128 .setStopOnFirstError (false )
133129 .executeProg (false )
@@ -136,9 +132,8 @@ public void warnsWhenOtherInstanceFieldIsReadAfterThisFieldWrite() {
136132 "package Test" ,
137133 "class Counter" ,
138134 " int value" ,
139- " function getOther(Counter other) returns int" ,
140- " value = 1" ,
141- " return other.value"
135+ " construct(Counter other)" ,
136+ " let _observed = other.value"
142137 );
143138 }
144139
@@ -152,9 +147,9 @@ public void warnsWhenOnlyOneArrayElementWasAssigned() {
152147 "package Test" ,
153148 "class Counter" ,
154149 " int values[2]" ,
155- " function getOther() returns int " ,
150+ " construct() " ,
156151 " values[0] = 1" ,
157- " return values[1]"
152+ " int observed = values[1]"
158153 );
159154 }
160155
@@ -300,18 +295,21 @@ public void doesNotWarnForInitializedExplicitReceiverInsideConstructor() {
300295 }
301296
302297 @ Test
303- public void warnsForUninitializedFieldReadFromPackageFunction () {
304- test ()
298+ public void doesNotWarnForUninitializedFieldReadFromPackageFunction () {
299+ CompilationResult result = test ()
305300 .setStopOnFirstError (false )
306301 .executeProg (false )
307- .expectWarning ("no explicit initializer and is not definitely assigned" )
308302 .lines (
309303 "package Test" ,
310304 "class Counter" ,
311305 " int value" ,
312306 "function read(Counter counter) returns int" ,
313307 " return counter.value"
314308 );
309+
310+ assertFalse (result .getGui ().getWarningList ().stream ()
311+ .anyMatch (w -> w .getMessage ().contains ("no explicit initializer and is not definitely assigned" )),
312+ result .getGui ().getWarningList ().toString ());
315313 }
316314
317315 @ Test
0 commit comments