-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41841 from poorna2152/fix_-41571
Fix invalid error for inaccessible module definitions in mapping constructor
- Loading branch information
Showing
7 changed files
with
231 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...src/test/java/org/ballerinalang/test/bala/expressions/MappingConstructorExprBalaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
* | ||
* WSO2 LLC. 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. | ||
*/ | ||
|
||
package org.ballerinalang.test.bala.expressions; | ||
|
||
import org.ballerinalang.test.BAssertUtil; | ||
import org.ballerinalang.test.BCompileUtil; | ||
import org.ballerinalang.test.BRunUtil; | ||
import org.ballerinalang.test.CompileResult; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Bala test cases for mapping constructor expression. | ||
* | ||
* @since 2201.9.0 | ||
*/ | ||
public class MappingConstructorExprBalaTest { | ||
|
||
@BeforeClass | ||
public void setup() { | ||
BCompileUtil.compileAndCacheBala("test-src/bala/test_projects/test_project"); | ||
} | ||
|
||
@Test | ||
public void testModuleConstantsInMappingConstructor() { | ||
CompileResult compileResult = | ||
BCompileUtil.compile("test-src/bala/test_bala/expressions/mapping_constructor_expr.bal"); | ||
BRunUtil.invoke(compileResult, "testModuleConstantsInMappingConstructor"); | ||
} | ||
|
||
@Test | ||
public void testMappingConstructorExprNegative() { | ||
CompileResult negativeCompileResult = BCompileUtil.compile( | ||
"test-src/bala/test_bala/expressions/mapping_constructor_expr_negative.bal"); | ||
int i = 0; | ||
BAssertUtil.validateError(negativeCompileResult, i++, | ||
"attempt to refer to non-accessible symbol 'MAPPING_NAME'", 24, 23); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "undefined symbol 'MAPPING_NAME'", 24, 23); | ||
BAssertUtil.validateError(negativeCompileResult, i++, | ||
"incompatible mapping constructor expression for type 'map<string>?'", 25, 22); | ||
BAssertUtil.validateError(negativeCompileResult, i++, | ||
"attempt to refer to non-accessible symbol 'MAPPING_NAME'", 25, 24); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "undefined symbol 'MAPPING_NAME'", 25, 24); | ||
BAssertUtil.validateError(negativeCompileResult, i++, | ||
"incompatible mapping constructor expression for type 'map<string>?'", 26, 22); | ||
BAssertUtil.validateError(negativeCompileResult, i++, | ||
"attempt to refer to non-accessible symbol 'MAPPING_NAME'", 26, 24); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "undefined symbol 'MAPPING_NAME'", 26, 24); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "attempt to refer to non-accessible symbol 'MAPPING_C'", | ||
26, 43); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "undefined symbol 'MAPPING_C'", 26, 43); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "missing non-defaultable required record field 'name'", | ||
27, 14); | ||
BAssertUtil.validateError(negativeCompileResult, i++, | ||
"attempt to refer to non-accessible symbol 'MAPPING_NAME'", 27, 16); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "undefined symbol 'MAPPING_NAME'", 27, 16); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "attempt to refer to non-accessible symbol 'MAPPING_C'", | ||
27, 35); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "undefined symbol 'MAPPING_C'", 27, 35); | ||
BAssertUtil.validateError(negativeCompileResult, i++, | ||
"incompatible mapping constructor expression for type '(map<string>|Rec)'", 28, 25); | ||
BAssertUtil.validateError(negativeCompileResult, i++, | ||
"attempt to refer to non-accessible symbol 'MAPPING_NAME'", 28, 27); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "undefined symbol 'MAPPING_NAME'", 28, 27); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "attempt to refer to non-accessible symbol 'MAPPING_C'", | ||
28, 46); | ||
BAssertUtil.validateError(negativeCompileResult, i++, "undefined symbol 'MAPPING_C'", 28, 46); | ||
Assert.assertEquals(negativeCompileResult.getErrorCount(), i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...-test/src/test/resources/test-src/bala/test_bala/expressions/mapping_constructor_expr.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. 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 testorg/foo; | ||
|
||
type Rec record { | ||
string name; | ||
}; | ||
|
||
function testModuleConstantsInMappingConstructor() { | ||
map<string> m1 = {[foo:MAPPING_A] : "A_VAL"}; | ||
assertEquals("A_VAL", m1["A"]); | ||
map<string> m2 = {[foo:MAPPING_A] : foo:MAPPING_B}; | ||
assertEquals("B", m2["A"]); | ||
map<string>? m3 = {[foo:MAPPING_A] : foo:MAPPING_B}; | ||
assertEquals("B", m3["A"]); | ||
map<string>|Rec m4 = {[foo:MAPPING_A] : foo:MAPPING_B}; | ||
assertEquals("B", m4["A"]); | ||
Rec r1 = {name: foo:MAPPING_A}; | ||
assertEquals("A", r1.name); | ||
Rec? r2 = {name: foo:MAPPING_A}; | ||
assertEquals("A", (<Rec>r2).name); | ||
} | ||
|
||
function assertEquals(anydata expected, anydata actual) { | ||
if expected != actual { | ||
panic error(string `expected ${expected.toBalString()}, found ${actual.toBalString()}`); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../test/resources/test-src/bala/test_bala/expressions/mapping_constructor_expr_negative.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. 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 testorg/foo; | ||
|
||
type Rec record { | ||
string name; | ||
}; | ||
|
||
public function testUnAccessibleModuleConstInMappingConstructor() { | ||
map<string> _ = {[foo:MAPPING_NAME]: "Amy"}; | ||
map<string>? _ = {[foo:MAPPING_NAME]: "Amy"}; | ||
map<string>? _ = {[foo:MAPPING_NAME]: foo:MAPPING_C}; | ||
Rec? _ = {[foo:MAPPING_NAME]: foo:MAPPING_C}; | ||
map<string>|Rec _ = {[foo:MAPPING_NAME]: foo:MAPPING_C}; | ||
} |
20 changes: 20 additions & 0 deletions
20
...-test/src/test/resources/test-src/bala/test_projects/test_project/mapping_constructor.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
// | ||
// WSO2 LLC. 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. | ||
|
||
public const MAPPING_A = "A"; | ||
public const MAPPING_B = "B"; | ||
const MAPPING_C = "C"; | ||
const MAPPING_NAME = "name"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters