Open lochana-chathura opened 2 years ago
Following also does not work.
function test1(int|string x) {
if x is int && !(x !is int) {
int _ = x; // Type not narrowed. Gives incompatible types: expected 'int', found 'other'
} else {
string _ = x; // Type not narrowed. Gives incompatible types: expected 'string', found '(string|int)'
}
}
When fixing this issue we need to clean up the comments added in PR #34964 for the following files.
TypeGuardTest.java
test_type_guard_type_narrow_4.bal
Following also does not work.
function test1(int|string x) { if x is int && !(x !is int) { int _ = x; // Type not narrowed. Gives incompatible types: expected 'int', found 'other' } else { string _ = x; // Type not narrowed. Gives incompatible types: expected 'string', found '(string|int)' } }
The first error here has been fixed in the current semtype integration changes.
Description: $subject. Consider the following code.
function test1(2|"foo" x) { if x is int && x == 2 { 2 _ = x; // OK } else { "foo" _ = x; // Gives expression of type 'never' or equivalent to type 'never' not allowed here } if x is 2 && x == 2 { 2 _ = x; // OK } else { "foo" _ = x; // Gives an issue expression of type 'never' or equivalent to type 'never' not allowed here } if x == 2 && x == 2 { 2 _ = x; // OK } else { "foo" _ = x; // Gives an issue expression of type 'never' or equivalent to type 'never' not allowed here } }
Affected Versions: 2201.0.0
These 3 errors too have been fixed in the current semtype integration changes.
Description: $subject. Consider the following code.
Affected Versions: 2201.0.0