-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Improvement]: Refactor BUnionType
's getMemberTypes()
usages
#43344
Comments
Fixed with 4f137ee |
When converting isSameType() usages to semtypes, here at Line 271 in d93ec61
the same BObjectType instance with one inside a BUnionType wrapper, evaluate not to be the same type, in the current compiler. We are comparing BUnionType 5262 to BObjectType 5231 With semTypes, they both identified to be the same type, causing NPE at later stage |
When rewriting Two places: Line 1098 in fe0509b
[2] Line 729 in fe0509b
Removing [1] fixed the issue. |
Found another issue related to type Obj0 distinct object {
function apply() returns int;
};
type Obj2 object {
function apply() returns int;
};
function foo(Obj0 x) {
Obj2 y = x; // Should have no error
} |
After rewriting Line 3588 in fe0509b
the following test that used compile will now give an error, class P1 {
Q1 q;
string p1;
function init() {
self.q = new;
self.p1 = "P1";
}
}
class Q1 {
P1 p;
string q1;
function init() {
self.p = new;
self.q1 = "Q1";
}
}
function testArraysOfCyclicDependentTypes3() returns P1[] {
P1[] arr = [];
arr[3] = new; // ERROR [test_parser.bal:(23:5,23:11)] cannot update 'readonly' value of type 'P1[]'
return arr;
}
function testArraysOfCyclicDependentTypes4() returns Q1[] {
Q1[] arr = [];
arr[3] = new; // ERROR [test_parser.bal:(29:5,29:11)] cannot update 'readonly' value of type 'Q1[]'
return arr;
} This is because in semtype |
const int[2]|[int, int] ERR_TUPLE5 = []; // ambiguous types With the use of |
Sample: function testBitWiseOperationsForNullable() {
byte? x = 251;
int:Signed8? y = -123;
var ans7 = x >> y;
} Replacing the following Line 2205 in b67b420
crash log (click to expand)
|
When replacing the stacktrace (click to expand)
public type Bdd Node|boolean;
public type Node readonly & record {|
int atom;
Bdd left;
Bdd middle;
Bdd right;
|}; The reason is in the Failing test: |
The reason for Hence, |
type X [(), (), (), (), int, (), (), string];
type Y [5.0]; |
Found an inconsistency in current interop method return type validation. function getNilAsReadOnly() returns error? = @java:Method { // <---------------[1]
'class: "org/ballerinalang/nativeimpl/jvm/tests/StaticMethods"
} external;
function getNilAsReadOnly() returns readonly = @java:Method { // <---------------[2]
'class: "org/ballerinalang/nativeimpl/jvm/tests/StaticMethods"
} external;
function getBooleanAsReadOnly() returns readonly = @java:Method { // <---------------[3]
'class: "org/ballerinalang/nativeimpl/jvm/tests/StaticMethods"
} external; java methods: public static void getNilAsReadOnly() {
}
public static boolean getBooleanAsReadOnly() {
return true;
} For [1] a compile error is given because Inconsistency is fixed with e70628b. In the new behavior all 3 cases are allowed. No compile error. |
import ballerina/test;
type IntOne 1;
type FloatOne 1.0;
type IntTwo 2;
type FloatTwo 2f;
function checkFiniteTypeEquality() {
IntOne intOne_1 = 1;
IntOne intOne_2 = 1;
IntTwo intTwo = 2;
FloatOne floatOne = 1f;
FloatTwo floatTwo = 2.0;
test:assertTrue((intOne_1 == intOne_2) && !(intOne_1 != intOne_2));
test:assertTrue((floatOne != floatTwo) && !(floatOne == floatTwo)); // error - line 16
test:assertFalse((intOne_1 == intTwo) && !(intOne_1 != intTwo)); // error - line 17
}
type Array ["array", 1];
type Mapping ["mapping", 2];
function checkTupleEqualityNegative() {
Array a = ["array", 1];
Mapping b = ["mapping", 2];
test:assertFalse(a == b); // error - line 26
}
//ERROR [test_parser.bal:(16:22,16:42)] operator '!=' not defined for 'FloatOne' and 'FloatTwo'
//ERROR [test_parser.bal:(16:49,16:69)] operator '==' not defined for 'FloatOne' and 'FloatTwo'
//ERROR [test_parser.bal:(17:23,17:41)] operator '==' not defined for 'IntOne' and 'IntTwo'
//ERROR [test_parser.bal:(17:48,17:66)] operator '!=' not defined for 'IntOne' and 'IntTwo'
//ERROR [test_parser.bal:(26:22,26:28)] operator '==' not defined for 'Array' and 'Mapping'
function checkEqualityOfMapsOfIncompatibleConstraintTypes() returns boolean {
map<int> a = {};
map<float> b = {};
boolean bool1 = a == b && !(a != b); // no error
map<string|int> c = {};
map<float> d = {};
boolean bool2 = c == d && !(c != d); // no error
return bool1 && bool2;
}
type EmployeeWithOptionalId record {|
string name;
float id?;
|};
type PersonWithOptionalId record {|
string name;
string id?;
|};
function checkEqualityOfRecordsOfIncompatibleTypes() returns boolean {
EmployeeWithOptionalId e1 = { name: "Maryam" };
PersonWithOptionalId p1 = { name: "Maryam" };
return b && e1 == p1 && !(e1 != p1); // no error
}
function readonlyEquality() returns boolean {
map<int> & readonly immutableMarks = {
math: 80,
physics: 85,
chemistry: 75
};
readonly readonlyMarks = immutableMarks;
map<int> marks = {
math: 80,
physics: 85,
chemistry: 75
};
return readonlyMarks != marks; // no error
}
function cannotDeepEqualReadonly() returns boolean {
readonly arr = [1, 2 , 3];
return arr == [1, 2 , 3]; // no Error
} According to equality-expr section in spec,
So the new behavior is correct. We need to improve the compile time error message.
function testUnreachabilityWithIfElseStmts6() {
10|20 e = 10;
if e == 10 {
int _ = 10;
} else if e == 20 {
int _ = 20;
} else if e == 10 { // New error: operator '==' not defined for 'never' and 'int'
never _ = e; // Previous error: unreachable code
}
} function testUnreachabilityWithIfStmtWithEqualityExpr15() {
True t = true;
False f = false;
if f == t { // New error: operator '==' not defined for 'false' and 'true'
return; // Previous error: unreachable code
} else if t == t {
string _ = "Ballerina";
} else {
string _ = "Ballerina"; // Previous error: unreachable code
}
} |
In case of inferred isolation, the isolated tag is added at With that fix In the previous Line 1535 in 8ef9be1
BTypeReferenceType wrapper as per the following logic.Lines 1531 to 1533 in 8ef9be1
Therefore, the resultant runtime type will not have the reference type name propagated. This caused the |
Please refer to ballerina-platform#43344 (comment) for the reason
Please refer to ballerina-platform#43344 (comment) for the reason
After rewriting the
function testTupleToJSONAssignmentNegative() {
xml A = xml `xml string`;
[string, int|xml, string...] C = ["text1", 1, A.toString()];
json jsonTest = <json[]>C; // No compile-time error for the cast.
}
type Teacher record {
readonly string name;
readonly int age;
string school;
};
type Customer record {
readonly int id;
readonly string name;
string lname;
};
type CustomerTable table<Customer|Teacher>;
CustomerTable tab3 = table key(name) [
{id: 13, name: "Foo", lname: "QWER"},
{id: 13, name: "Bar", lname: "UYOR"}
];
type Customer2 record {|
int id;
string name;
string lname;
|};
type CustomerEmptyKeyedTbl table<Customer2> key();
function testCastingWithEmptyKeyedKeylessTbl() {
CustomerEmptyKeyedTbl tbl1 = <CustomerEmptyKeyedTbl>tab3; // No compile-time error for the cast.
table<record {
int id;
string name;
string lname;
}> key() tbl = <table<record {
int id;
string name;
string lname;
}> key()>tab3; // No compile-time error for the cast.
} In both cases, non-empty intersections exist. Therefore new behavior is acceptable. Need to make sure these casts are not crashing at runtime.
type Student record {
int index;
int age;
};
type Person record {
string name;
int age;
string address;
};
function testInvalidStructEquivalentCastCaseTwo() returns (map<Student>) {
map<Person> testPMap = {};
map<Student> testSMap = <map<Student>>testPMap; // No compile-time error for the cast.
return testSMap;
} This is because
function testTypeCastInConstructorMemberWithUnionCETNegative() {
string[]|int val1 = [];
byte[] a = <byte[]> val1; // No compile-time error for the cast.
} Similarly, this is allowed because
public class person01 {
public int age = 0;
public string name = "";
public string address = "";
}
public class employee01 {
public int age = 0;
public string name = "";
public string zipcode = "95134";
function init (int age, string name) {
self.age = age;
self.name = name;
}
}
function f5() returns string {
employee01 e = new (14, "rat");
person01 p = <person01> e; // No compile-time error for the cast.
return p.name;
} Out of the above ones, 1, 3, 4, and 5 give errors at runtime. 2 runs without any errors. Relevant commit: 3c58404 |
After rewriting function testNeverRuntime10() {
int x = 100;
boolean b = x is never; // incompatible types: 'int' will not be matched to 'never'
assertEquality(false, b);
}
type Record record {|
int i;
never[] j;
|};
function testNeverRuntime11() {
Record x = { i: 1, j: [] };
boolean b = x is never; // incompatible types: 'Record' will not be matched to 'never'
assertEquality(false, b);
} function testNeverFieldTypeCheck() {
record {int x;} r2 = {x: 2, "color": "blue"};
assertEquality(false, r2 is record {never x?;}); // incompatible types: 'record {| int x; anydata...; |}' will not be matched to 'record {| never x?; anydata...; |}'
record {never? x;} r3 = {x: (), "color": "blue"};
assertEquality(false, r3 is record {never x?;}); // incompatible types: 'record {| never? x; anydata...; |}' will not be matched to 'record {| never x?; anydata...; |}'
record {int? x;} r4 = {x: 2, "color": "blue"};
assertEquality(false, r4 is record {never x?;}); // incompatible types: 'record {| int? x; anydata...; |}' will not be matched to 'record {| never x?; anydata...; |}'
record {int x;} & readonly v3 = {x: 2, "color": "blue"};
assertEquality(false, v3 is record {never x?;}); // incompatible types: '(record {| int x; anydata...; |} & readonly)' will not be matched to 'record {| never x?; anydata...; |}'
record {never? x;} & readonly v4 = {x: (), "color": "blue"};
assertEquality(false, v4 is record {never x?;}); // incompatible types: '(record {| never? x; anydata...; |} & readonly)' will not be matched to 'record {| never x?; anydata...; |}'
} |
Description
$subject. We need to get rid of
getMemberTypes()
andgetOriginalMemberTypes()
usages in the current compiler, in order to do #43343.This issue depends on #43126 which is in PR sent state now.
The text was updated successfully, but these errors were encountered: