Skip to content

Commit

Permalink
Add non public access tests
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Mar 14, 2024
1 parent 49c9b56 commit 71061b3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1355,9 +1355,10 @@ private BType checkTupleType(BTupleType tupleType, BLangListConstructorExpr list
}

private BTupleType createNewTupleType(Location pos, List<BType> memberTypes, AnalyzerData data) {
SymbolEnv symbolEnv = data.env;
BTypeSymbol tupleTypeSymbol =
Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, Flags.PUBLIC, Names.EMPTY,
data.env.enclPkg.symbol.pkgID, null, data.env.scope.owner, pos, SOURCE);
Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, Flags.PUBLIC, Names.EMPTY, symbolEnv.enclPkg.symbol.pkgID,
null, symbolEnv.scope.owner, pos, SOURCE);
List<BTupleMember> members = new ArrayList<>();
memberTypes.forEach(m ->
members.add(new BTupleMember(m, Symbols.createVarSymbolForTupleMember(m))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ public void testNegative() {
"cannot update 'readonly' value of type '[1,\"f\",\"g\"] & readonly'", 30, 5);
BAssertUtil.validateError(compileResult, i++, "incompatible types: expected '(1|\"f\"|\"g\")', found 'string'",
30, 12);
BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 34, 17);
BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 35, 18);
BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l13'", 34, 17);
BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l14'", 35, 18);
BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l10'", 39, 15);
BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 39, 15);
BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l11'", 40, 29);
BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 40, 29);
BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l12'", 41, 18);
BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l12'", 41, 18);
Assert.assertEquals(compileResult.getErrorCount(), i);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ function testInvalidUpdates() {
}

function testUndefinedMemberAccess() {
float[] _ = foo:l10;
string[] _ = foo:l11;
float[] _ = foo:l13;
string[] _ = foo:l14;
}

function testNonPublicConstAccess() {
int[] _ = foo:l10;
[int, int, boolean] _ = foo:l11;
string[] _ = foo:l12;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ public const IntArr l6 = [1, 2, 3];
public const [int, string...] l7 = [1, "f", "g"];
public const (string|int)[][] l8 = [[1, "2", 3], [4, 5, 6]];
public const [(string[]|int[])...] l9 = [[1, 2, 3], ["4", "5", "6"]];
const int[] l10 = [1, 2, 3];
const [int, int, boolean] l11 = [1, 2, true];
const l12 = l1;

0 comments on commit 71061b3

Please sign in to comment.