From c1dd245eb02663c0288d25b568d4cc2148c9b7cd Mon Sep 17 00:00:00 2001 From: niveathika Date: Tue, 17 Oct 2023 11:14:08 +0530 Subject: [PATCH] Fix class cast expression for use of local variables --- changelog.md | 1 + .../sql/compiler/codemodifier/PersistQueryValidator.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/changelog.md b/changelog.md index f15edfd..1121bba 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed +- [Fix class cast exception when executing query with non-global variable](https://github.com/ballerina-platform/persist-tools/issues/311) ## [1.2.0] - 2023-09-18 diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/sql/compiler/codemodifier/PersistQueryValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/sql/compiler/codemodifier/PersistQueryValidator.java index e6c7def..0d5a909 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/sql/compiler/codemodifier/PersistQueryValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/sql/compiler/codemodifier/PersistQueryValidator.java @@ -208,6 +208,11 @@ public void perform(SyntaxNodeAnalysisContext ctx) { private Query isQueryUsingPersistentClient(FromClauseNode fromClauseNode) { if (fromClauseNode.expression() instanceof ClientResourceAccessActionNode remoteCall) { + if (remoteCall.expression().kind() != SyntaxKind.SIMPLE_NAME_REFERENCE) { + // This improvement is tracked in + // https://github.com/ballerina-platform/ballerina-standard-library/issues/4943 + return null; + } SimpleNameReferenceNode clientName = (SimpleNameReferenceNode) remoteCall.expression(); Collection clientResourceChildEntries = remoteCall.childEntries(); if (clientResourceChildEntries.size() == 5 || clientResourceChildEntries.size() == 7) {