From a41fefc17050a9c4eb3183433161ff17839b3cc8 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 16 Dec 2024 17:05:18 -0800 Subject: [PATCH 1/2] improve error message for duplicate super.init Signed-off-by: Jade Abraham --- compiler/passes/initializerRules.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/passes/initializerRules.cpp b/compiler/passes/initializerRules.cpp index f470ab55e8ba..abcca78e2071 100644 --- a/compiler/passes/initializerRules.cpp +++ b/compiler/passes/initializerRules.cpp @@ -513,7 +513,10 @@ static InitNormalize preNormalize(AggregateType* at, } else if (isSuperInit(callExpr) == true) { Expr* next = callExpr->next; - INT_ASSERT(state.isPhase0() == true); + if (state.isPhase0() != true) { + USR_FATAL(callExpr, + "duplicate use of 'super.init()' in initializer, this should only be called once"); + } state.completePhase0(callExpr); if (at->isRecord() == true) { From d496cd5dd59ef12cb7771592d6ac707ab493efdb Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 16 Dec 2024 17:05:26 -0800 Subject: [PATCH 2/2] add test case Signed-off-by: Jade Abraham --- .../inheritance/duplicate-super-init.chpl | 11 +++++++++++ .../inheritance/duplicate-super-init.good | 2 ++ 2 files changed, 13 insertions(+) create mode 100644 test/classes/initializers/inheritance/duplicate-super-init.chpl create mode 100644 test/classes/initializers/inheritance/duplicate-super-init.good diff --git a/test/classes/initializers/inheritance/duplicate-super-init.chpl b/test/classes/initializers/inheritance/duplicate-super-init.chpl new file mode 100644 index 000000000000..68b9ab0d2175 --- /dev/null +++ b/test/classes/initializers/inheritance/duplicate-super-init.chpl @@ -0,0 +1,11 @@ +class P { } +class C: P { + proc init() { + super.init(); + super.init(); + } +} + +proc main() { + var c = new C(); +} diff --git a/test/classes/initializers/inheritance/duplicate-super-init.good b/test/classes/initializers/inheritance/duplicate-super-init.good new file mode 100644 index 000000000000..2ee8aec2b7fe --- /dev/null +++ b/test/classes/initializers/inheritance/duplicate-super-init.good @@ -0,0 +1,2 @@ +duplicate-super-init.chpl:3: In initializer: +duplicate-super-init.chpl:5: error: duplicate use of 'super.init()' in initializer, this should only be called once