Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ushirask committed Aug 15, 2023
1 parent 778a659 commit 21c0b39
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ public void testNegativeCases() {
392, 9);
validateError(negativeResult, i++, "incompatible types: expected 'int', found '(string|int)'",
396, 9);
validateError(negativeResult, i++, "incompatible types: expected 'int', found 'STRINT'",
validateError(negativeResult, i++, "incompatible types: expected 'int', found 'StrOrInt1'",
399, 9);
validateError(negativeResult, i++, "incompatible types: expected 'int', found '(string|int)'",
403, 7);
validateError(negativeResult, i++, "incompatible types: expected 'int', found '(int|STR)'",
validateError(negativeResult, i++, "incompatible types: expected 'int', found '(int|Str)'",
406, 7);
Assert.assertEquals(negativeResult.getErrorCount(), i);
}
Expand Down Expand Up @@ -544,8 +544,8 @@ public void testNestedMemberAccessOnIntersectionTypes() {
}

@Test
public void testNestedMemberAccessWithSameTypeUnionExprAsIndex() {
BRunUtil.invoke(result, "testUnionTypeExprMemberAccess");
public void testMemberAccessWithUnionTypedIndexExpr() {
BRunUtil.invoke(result, "testMemberAccessWithUnionTypedIndexExpr");
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,11 +1178,12 @@ function testUnspecifiedFieldRecordMemberAccessWithStringCharKeyExpr() {
assertTrue(v is ());
}

type INT int;
type INT2 int|int:Signed16;
type STR2 string|string:Char;
type IntType1 int;
type IntType2 int|int:Signed16;
type StrType1 string|string:Char;
type IntType3 1|2|3|4;

function testUnionTypeExprMemberAccess() {
function testMemberAccessWithUnionTypedIndexExpr() {
record {|
int a;
|} r = {a: 1};
Expand Down Expand Up @@ -1213,7 +1214,7 @@ function testUnionTypeExprMemberAccess() {
assertEquality("d", arr1[1]);

[string, int] t1 = ["a", 1];
int|INT|int y1 = 0;
int|IntType1|int y1 = 0;
t1[y1] = "b";
assertEquality("b", t1[0]);

Expand All @@ -1226,14 +1227,36 @@ function testUnionTypeExprMemberAccess() {
string a;
int b;
|} r2 = {a: "a", b: 1};
string|STR2 s2 = "b";
string|StrType1 s2 = "b";
r2[s2] = 2;
assertEquality(2, r2.b);

float[] arr2 = [0.1, 1.2, 2.3];
INT2|int:Signed8 x2 = 0;
IntType2|int:Signed8 x2 = 0;
arr2[x2] = 4.5;
assertEquality(4.5, arr2[0]);

int[] arr3 = [1, 2, 3];
int|IntType3 x3 = 1;
arr3[x3] = 4;
assertEquality(4, arr3[1]);

record {|
int a;
|} r3 = {a: 1};
"a"|"b" s3 = "a";
r3[s3] = 2;
assertEquality(2, r3.a);

[int, string] tup = [1, "x"];
0|1|int a = 0;
tup[a] = 4;
assertEquality(4, tup[0]);

[int, string] tup2 = [1, "x"];
0|1|2 a2 = 1;
tup2[a2] = "y";
assertEquality("y", tup2[1]);
}

const ASSERTION_ERROR_REASON = "AssertionError";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ function testCustomTupleTypesAccessNegative() {
boolean _ = x14; //error: incompatible types: expected 'boolean', found 'int'
}

type STR string;
type STRINT string|int;
type Str string;
type StrOrInt1 string|int;

function testMemberAccessWithInvalidUnionTypeExpr() {
function testMemberAccessWithUnionTypedIndexExprNegative() {
record {|
int a;
|} r = {a: 1};
Expand All @@ -395,13 +395,13 @@ function testMemberAccessWithInvalidUnionTypeExpr() {
string|int x2 = 1;
arr[x2] = 4; // error: incompatible types: expected 'int', found '(string|int)'

STRINT x3 = 2;
arr[x3] = "4"; // error: incompatible types: expected 'int', found 'STRINT'
StrOrInt1 x3 = 2;
arr[x3] = "4"; // error: incompatible types: expected 'int', found 'StrOrInt1'

[string, int] t = ["a", 1];
string|int y = 0;
t[y] = "b"; // error: incompatible types: expected 'int', found '(string|int)'

int|STR y2 = 1;
t[y2] = 0; // error: incompatible types: expected 'int', found '(int|STR)'
int|Str y2 = 1;
t[y2] = 0; // error: incompatible types: expected 'int', found '(int|Str)'
}

0 comments on commit 21c0b39

Please sign in to comment.