Skip to content

Commit

Permalink
Merge pull request #1106 from Bhashinee/master
Browse files Browse the repository at this point in the history
Fix the compilation error when there is a constant or configurable given as included param
  • Loading branch information
Bhashinee authored May 15, 2024
2 parents 15e71dd + 5688911 commit 7d90eba
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Diagnostic> errorDiagnosticsList = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR))
.collect(Collectors.toList());
Assert.assertEquals(errorDiagnosticsList.size(), 0);
}

private void assertValues(List<Diagnostic> errorDiagnosticsList) {
long availableErrors = errorDiagnosticsList.size();
Assert.assertEquals(availableErrors, 5);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "cache_test"
name = "sample7"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}

Expand Down

0 comments on commit 7d90eba

Please sign in to comment.