From ca7ec9ccb54915b937ea0183df5bb39d63f976f4 Mon Sep 17 00:00:00 2001 From: "Flavio S. Glock" Date: Fri, 13 Mar 2026 16:13:35 +0100 Subject: [PATCH] Fix variable redeclaration warnings to match system Perl - `our` variables now show "redeclared" instead of "masks earlier declaration" - `my` variables now show "masks earlier declaration in same scope" - Removed "Warning:" prefix to match system Perl format - Fixed typo "ctx.symbolTable" to "scope" in warning message Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin --- .../java/org/perlonjava/backend/jvm/EmitVariable.java | 7 ++++--- .../org/perlonjava/frontend/parser/OperatorParser.java | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/perlonjava/backend/jvm/EmitVariable.java b/src/main/java/org/perlonjava/backend/jvm/EmitVariable.java index c484a205b..f0e4c5a52 100644 --- a/src/main/java/org/perlonjava/backend/jvm/EmitVariable.java +++ b/src/main/java/org/perlonjava/backend/jvm/EmitVariable.java @@ -1096,11 +1096,12 @@ static void handleMyOperator(EmitterVisitor emitterVisitor, OperatorNode node) { if (CompilerOptions.DEBUG_ENABLED) emitterVisitor.ctx.logDebug("MY " + operator + " " + sigil + name); if (emitterVisitor.ctx.symbolTable.getVariableIndexInCurrentScope(var) != -1) { if (Warnings.warningManager.isWarningEnabled("redefine")) { + String message = operator.equals("our") + ? "\"" + operator + "\" variable " + var + " redeclared" + : "\"" + operator + "\" variable " + var + " masks earlier declaration in same scope"; System.err.println( emitterVisitor.ctx.errorUtil.errorMessage(node.getIndex(), - "Warning: \"" + operator + "\" variable " - + var - + " masks earlier declaration in same ctx.symbolTable")); + message)); } } int varIndex = emitterVisitor.ctx.symbolTable.addVariable(var, operator, sigilNode); diff --git a/src/main/java/org/perlonjava/frontend/parser/OperatorParser.java b/src/main/java/org/perlonjava/frontend/parser/OperatorParser.java index ce48e6ec6..ad8e9c69a 100644 --- a/src/main/java/org/perlonjava/frontend/parser/OperatorParser.java +++ b/src/main/java/org/perlonjava/frontend/parser/OperatorParser.java @@ -234,11 +234,11 @@ private static void addVariableToScope(EmitterContext ctx, String operator, Oper String name = ((IdentifierNode) identifierNode).name; String var = sigil + name; if (ctx.symbolTable.getVariableIndexInCurrentScope(var) != -1) { + String message = operator.equals("our") + ? "\"" + operator + "\" variable " + var + " redeclared" + : "\"" + operator + "\" variable " + var + " masks earlier declaration in same scope"; System.err.println( - ctx.errorUtil.errorMessage(node.getIndex(), - "Warning: \"" + operator + "\" variable " - + var - + " masks earlier declaration in same ctx.symbolTable")); + ctx.errorUtil.errorMessage(node.getIndex(), message)); } int varIndex = ctx.symbolTable.addVariable(var, operator, node); // Note: the isDeclaredReference flag is stored in node.annotations