Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,13 @@ private void visit(ModuleDef moduleDef) {
}

private void visit(ExprDestroy stmtDestroy) {
if (stmtDestroy.getDestroyedObj() instanceof ExprThis) {
if (isInConstructor(stmtDestroy)) {
stmtDestroy.addError("Cannot destroy 'this' in constructor");
return;
}
}

WurstType typ = stmtDestroy.getDestroyedObj().attrTyp();
if (typ instanceof WurstTypeModule) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,6 @@ public void minusRewrite() {
);
}


@Test
public void duplicateNameInClassHierachy() {
testAssertErrorsLines(false, "Variable x in class B hides variable x from superclass A",
Expand All @@ -1459,5 +1458,19 @@ public void duplicateNameInClassHierachy() {
"endpackage");
}

@Test
public void callingDestroyThisInConstructor() {
testAssertErrorsLines(false, "Cannot destroy 'this' in constructor",
"package test",
"native testSuccess()",
"class A",
" construct()",
" destroy this",
"init",
" let b = new A()",
" if b != null",
" testSuccess()",
"endpackage");
}

}
Loading