diff --git a/changelog.md b/changelog.md index 24ecca2f..f23ca10c 100644 --- a/changelog.md +++ b/changelog.md @@ -4,7 +4,11 @@ This file contains all the notable changes done to the Ballerina Cache package t The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [unreleased] +### Fixed +- [Fix the compilation failure when constants and configurables are used in cache config as included params](https://github.com/ballerina-platform/ballerina-library/issues/6036) + +## [3.7.1] - 2024-01-11 ### Fixed - [Fix the compilation failure when constants are used in cache config](https://github.com/ballerina-platform/ballerina-library/issues/5915) diff --git a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java index fd22083b..e060566d 100644 --- a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java +++ b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/cache/compiler/CompilerPluginTest.java @@ -117,6 +117,16 @@ public void testConfigWithConstants() { Assert.assertEquals(errorDiagnosticsList.size(), 0); } + @Test(description = "Tests whether there are no compilation failures for constants and configurables as included " + + "params. Those validations will be ignored.") + public void testConfigWithIncludedParams() { + DiagnosticResult diagnosticResult = loadPackage("sample7").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 0); + } + private void assertValues(List errorDiagnosticsList) { long availableErrors = errorDiagnosticsList.size(); Assert.assertEquals(availableErrors, 5); diff --git a/compiler-plugin-tests/src/test/resources/diagnostics/sample7/Ballerina.toml b/compiler-plugin-tests/src/test/resources/diagnostics/sample7/Ballerina.toml new file mode 100644 index 00000000..38ad123e --- /dev/null +++ b/compiler-plugin-tests/src/test/resources/diagnostics/sample7/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "cache_test" +name = "sample7" +version = "0.1.0" diff --git a/compiler-plugin-tests/src/test/resources/diagnostics/sample7/main.bal b/compiler-plugin-tests/src/test/resources/diagnostics/sample7/main.bal new file mode 100644 index 00000000..99670a22 --- /dev/null +++ b/compiler-plugin-tests/src/test/resources/diagnostics/sample7/main.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org). +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/cache; + +configurable int capacity = 300; +const decimal CACHE_CLEANUP_INTERVAL = 900.0; + +public function main() returns error? { + cache:Cache cache = new(capacity = capacity , evictionFactor = 0.2, defaultMaxAge = 86400, cleanupInterval = CACHE_CLEANUP_INTERVAL); +} diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java index 8f1a7d6a..de6f3442 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheConfigValidator.java @@ -218,9 +218,11 @@ private void validateConfig(String name, String value, SyntaxNodeAnalysisContext break; } } catch (NumberFormatException e) { - reportDiagnostic(ctx, location, DiagnosticsCodes.CACHE_106.getErrorCode(), - DiagnosticsCodes.CACHE_106.getError() + e.getMessage(), - DiagnosticsCodes.CACHE_106.getSeverity()); + // This occurs when there is a variable reference in the value in scenarios like having a + // constant or configurable. In such cases like configurable, we cannot validate the value as the value is + // resolved at runtime. Hence, ignoring the validation. And for constants, if they are not in the same file, + // we cannot read them from the compiler plugin. Hence, ignoring the validation. These will be validated + // runtime. } }