File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/java/de/peeeq/wurstscript/validation
test/java/tests/wurstscript/tests Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -1863,6 +1863,13 @@ private void visit(ModuleDef moduleDef) {
18631863 }
18641864
18651865 private void visit (ExprDestroy stmtDestroy ) {
1866+ if (stmtDestroy .getDestroyedObj () instanceof ExprThis ) {
1867+ if (isInConstructor (stmtDestroy )) {
1868+ stmtDestroy .addError ("Cannot destroy 'this' in constructor" );
1869+ return ;
1870+ }
1871+ }
1872+
18661873 WurstType typ = stmtDestroy .getDestroyedObj ().attrTyp ();
18671874 if (typ instanceof WurstTypeModule ) {
18681875
Original file line number Diff line number Diff line change @@ -1442,7 +1442,6 @@ public void minusRewrite() {
14421442 );
14431443 }
14441444
1445-
14461445 @ Test
14471446 public void duplicateNameInClassHierachy () {
14481447 testAssertErrorsLines (false , "Variable x in class B hides variable x from superclass A" ,
@@ -1459,5 +1458,19 @@ public void duplicateNameInClassHierachy() {
14591458 "endpackage" );
14601459 }
14611460
1461+ @ Test
1462+ public void callingDestroyThisInConstructor () {
1463+ testAssertErrorsLines (false , "Cannot destroy 'this' in constructor" ,
1464+ "package test" ,
1465+ "native testSuccess()" ,
1466+ "class A" ,
1467+ " construct()" ,
1468+ " destroy this" ,
1469+ "init" ,
1470+ " let b = new A()" ,
1471+ " if b != null" ,
1472+ " testSuccess()" ,
1473+ "endpackage" );
1474+ }
14621475
14631476}
You can’t perform that action at this time.
0 commit comments