File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
main/java/de/peeeq/wurstscript/validation
test/java/tests/wurstscript/tests Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -1817,6 +1817,13 @@ private void visit(ModuleDef moduleDef) {
18171817 }
18181818
18191819 private void visit (ExprDestroy stmtDestroy ) {
1820+ if (stmtDestroy .getDestroyedObj () instanceof ExprThis ) {
1821+ if (isInConstructor (stmtDestroy )) {
1822+ stmtDestroy .addError ("Cannot destroy 'this' in constructor" );
1823+ return ;
1824+ }
1825+ }
1826+
18201827 WurstType typ = stmtDestroy .getDestroyedObj ().attrTyp ();
18211828 if (typ instanceof WurstTypeModule ) {
18221829
Original file line number Diff line number Diff line change @@ -1442,5 +1442,35 @@ public void minusRewrite() {
14421442 );
14431443 }
14441444
1445+ @ Test
1446+ public void duplicateNameInClassHierachy () {
1447+ testAssertErrorsLines (false , "Variable x in class B hides variable x from superclass A" ,
1448+ "package test" ,
1449+ "native testSuccess()" ,
1450+ "class A" ,
1451+ " int x" ,
1452+ "class B extends A" ,
1453+ " int x" ,
1454+ "init" ,
1455+ " let b = new B()" ,
1456+ " if b != null" ,
1457+ " testSuccess()" ,
1458+ "endpackage" );
1459+ }
1460+
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+ }
14451475
14461476}
You can’t perform that action at this time.
0 commit comments