From c616731a67ca63121d5e2e06298e75abf7f62620 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Thu, 19 Oct 2023 16:22:27 +0530 Subject: [PATCH 1/3] Fix unwanted configurable error --- .../compiler/semantics/analyzer/SemanticAnalyzer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index 23f4b6074219..a04427a79048 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -1156,9 +1156,11 @@ public void visit(BLangSimpleVariable varNode, AnalyzerData data) { BType lhsType = varNode.symbol.type; varNode.setBType(lhsType); - // Configurable variable type must be a subtype of anydata. if (configurable && varNode.typeNode != null) { + if (lhsType.tag == TypeTags.SEMANTIC_ERROR) { + return; + } if (!types.isAssignable(lhsType, symTable.anydataType)) { dlog.error(varNode.typeNode.pos, DiagnosticErrorCode.CONFIGURABLE_VARIABLE_MUST_BE_ANYDATA); From 39be4fcec9be593b101d0d4c9168e19ca11481d1 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Thu, 19 Oct 2023 16:22:35 +0530 Subject: [PATCH 2/3] Add unit test --- .../test/types/globalvar/GlobalVarNegativeTest.java | 2 +- .../variabledef/configurable_global_var_decl_negative.bal | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/globalvar/GlobalVarNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/globalvar/GlobalVarNegativeTest.java index fb21d2fbf8d0..b689d1eeddd5 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/globalvar/GlobalVarNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/globalvar/GlobalVarNegativeTest.java @@ -174,7 +174,7 @@ public void testConfigurableModuleVarDeclNegative() { BAssertUtil.validateError(result, i++, "configurable variable currently not supported for " + "'(table> & readonly)'\n\t" + "map constraint type '()' is not supported", 106, 1); - + BAssertUtil.validateError(result, i++, "redeclared symbol 'host'", 110, 18); Assert.assertEquals(result.getErrorCount(), i); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/statements/variabledef/configurable_global_var_decl_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/statements/variabledef/configurable_global_var_decl_negative.bal index ea06c58c23c4..fc7ff0818bbd 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/statements/variabledef/configurable_global_var_decl_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/statements/variabledef/configurable_global_var_decl_negative.bal @@ -104,3 +104,7 @@ configurable string? nilUnion = ?; configurable map<()> nilMap = ?; configurable Person6 nilRecord1 = ?; configurable table> nilTable = ?; + +// Redeclared configurable variable +configurable string host = ?; +configurable int host = ?; From be0bbb4f6736840c757d2b9315376a2eec75c481 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Wed, 1 Nov 2023 15:58:52 +0530 Subject: [PATCH 3/3] Address review suggestion --- .../compiler/semantics/analyzer/SemanticAnalyzer.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index a04427a79048..0480da7db910 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -1157,10 +1157,7 @@ public void visit(BLangSimpleVariable varNode, AnalyzerData data) { BType lhsType = varNode.symbol.type; varNode.setBType(lhsType); // Configurable variable type must be a subtype of anydata. - if (configurable && varNode.typeNode != null) { - if (lhsType.tag == TypeTags.SEMANTIC_ERROR) { - return; - } + if (configurable && varNode.typeNode != null && lhsType.tag != TypeTags.SEMANTIC_ERROR) { if (!types.isAssignable(lhsType, symTable.anydataType)) { dlog.error(varNode.typeNode.pos, DiagnosticErrorCode.CONFIGURABLE_VARIABLE_MUST_BE_ANYDATA);