From 14451806dc1d11b82b3470ce1e000e8ebdc51d18 Mon Sep 17 00:00:00 2001 From: gimantha Date: Sun, 17 Nov 2024 18:58:54 +0530 Subject: [PATCH 1/4] Fix #40606 --- .../semantics/analyzer/TypeChecker.java | 27 ++++++++++++------- ...lientResourceAccessActionNegativeTest.java | 8 ------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index cef5cdbdf1a3..2f70a9d1d1c8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -4085,17 +4085,26 @@ public void visit(BLangInvocation.BLangResourceAccessInvocation resourceAccessIn handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments, resourceAccessInvocation.name.pos, DiagnosticErrorCode.UNDEFINED_RESOURCE_METHOD, data, resourceAccessInvocation.name, lhsExprType); + return; } else if (targetResourceFuncCount > 1) { - handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments, resourceAccessInvocation.pos, - DiagnosticErrorCode.AMBIGUOUS_RESOURCE_ACCESS_NOT_YET_SUPPORTED, data, lhsExprType); - } else { - BResourceFunction targetResourceFunc = resourceFunctions.get(0); - checkExpr(resourceAccessInvocation.resourceAccessPathSegments, - getResourcePathType(targetResourceFunc.pathSegmentSymbols), data); - resourceAccessInvocation.symbol = targetResourceFunc.symbol; - resourceAccessInvocation.targetResourceFunc = targetResourceFunc; - checkResourceAccessParamAndReturnType(resourceAccessInvocation, targetResourceFunc, data); + //Filter the resource function with identifier segment + Optional first = resourceFunctions.stream().filter(func -> func.pathSegmentSymbols + .get(func.pathSegmentSymbols.size() - 1).kind == SymbolKind.RESOURCE_PATH_IDENTIFIER_SEGMENT) + .findFirst(); + if (first.isPresent()) { + resourceFunctions = new ArrayList<>(List.of(first.get())); + } else { + handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments, resourceAccessInvocation.pos, + DiagnosticErrorCode.AMBIGUOUS_RESOURCE_ACCESS_NOT_YET_SUPPORTED, data, lhsExprType); + return; + } } + BResourceFunction targetResourceFunc = resourceFunctions.get(0); + checkExpr(resourceAccessInvocation.resourceAccessPathSegments, + getResourcePathType(targetResourceFunc.pathSegmentSymbols), data); + resourceAccessInvocation.symbol = targetResourceFunc.symbol; + resourceAccessInvocation.targetResourceFunc = targetResourceFunc; + checkResourceAccessParamAndReturnType(resourceAccessInvocation, targetResourceFunc, data); } private void handleResourceAccessError(BLangListConstructorExpr resourceAccessPathSegments, diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/action/ClientResourceAccessActionNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/action/ClientResourceAccessActionNegativeTest.java index 7ddf03eb3a50..1d1aea552a4d 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/action/ClientResourceAccessActionNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/action/ClientResourceAccessActionNegativeTest.java @@ -124,18 +124,10 @@ public void testClientResourceCallNegative() { "too many arguments in call to 'post()'", 90, 13); validateError(clientResourceAccessNegative, index++, "too many arguments in call to 'post()'", 91, 13); - validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " + - "supported when the corresponding resource method is ambiguous", 145, 13); - validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " + - "supported when the corresponding resource method is ambiguous", 146, 13); - validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " + - "supported when the corresponding resource method is ambiguous", 147, 13); validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " + "supported when the corresponding resource method is ambiguous", 148, 13); validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " + "supported when the corresponding resource method is ambiguous", 149, 13); - validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " + - "supported when the corresponding resource method is ambiguous", 150, 13); validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " + "supported when the corresponding resource method is ambiguous", 151, 13); validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " + From 8b3ca8e84b06d8e90ae2d829c1d48c6b6949a921 Mon Sep 17 00:00:00 2001 From: gimantha Date: Sun, 17 Nov 2024 21:35:56 +0530 Subject: [PATCH 2/4] Fix checkstyle issue --- .../compiler/semantics/analyzer/TypeChecker.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index 2f70a9d1d1c8..90ec06d21bdc 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -4094,8 +4094,9 @@ public void visit(BLangInvocation.BLangResourceAccessInvocation resourceAccessIn if (first.isPresent()) { resourceFunctions = new ArrayList<>(List.of(first.get())); } else { - handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments, resourceAccessInvocation.pos, - DiagnosticErrorCode.AMBIGUOUS_RESOURCE_ACCESS_NOT_YET_SUPPORTED, data, lhsExprType); + handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments, + resourceAccessInvocation.pos, DiagnosticErrorCode.AMBIGUOUS_RESOURCE_ACCESS_NOT_YET_SUPPORTED, + data, lhsExprType); return; } } From 06a71a1dcac7229e74071866f37ff0678b14653c Mon Sep 17 00:00:00 2001 From: gimantha Date: Sun, 17 Nov 2024 23:24:56 +0530 Subject: [PATCH 3/4] Fix test failure --- .../api/test/actions/SymbolsInResourceAccessActionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/actions/SymbolsInResourceAccessActionTest.java b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/actions/SymbolsInResourceAccessActionTest.java index 0916a5d733f7..d75f7728a8f3 100644 --- a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/actions/SymbolsInResourceAccessActionTest.java +++ b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/actions/SymbolsInResourceAccessActionTest.java @@ -166,7 +166,7 @@ public Object[][] getResourceAccessActionPathPos() { @Test public void testPathSegmentOfAmbiguousResourceFunction() { Optional symbol = model.symbol(srcFile, LinePosition.from(91, 9)); - assertTrue(symbol.isEmpty()); // Resource method is ambiguous + assertTrue(symbol.isPresent()); // Resource method is ambiguous } // Utils From d0b026e5d86f95eec83cf157c58a30e60c89d64b Mon Sep 17 00:00:00 2001 From: Gimantha Bandara Date: Sun, 17 Nov 2024 23:26:01 +0530 Subject: [PATCH 4/4] Update tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/actions/SymbolsInResourceAccessActionTest.java --- .../api/test/actions/SymbolsInResourceAccessActionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/actions/SymbolsInResourceAccessActionTest.java b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/actions/SymbolsInResourceAccessActionTest.java index d75f7728a8f3..dc12244b66fd 100644 --- a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/actions/SymbolsInResourceAccessActionTest.java +++ b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/actions/SymbolsInResourceAccessActionTest.java @@ -166,7 +166,7 @@ public Object[][] getResourceAccessActionPathPos() { @Test public void testPathSegmentOfAmbiguousResourceFunction() { Optional symbol = model.symbol(srcFile, LinePosition.from(91, 9)); - assertTrue(symbol.isPresent()); // Resource method is ambiguous + assertTrue(symbol.isPresent()); } // Utils