ballerina-lang
ballerina-lang copied to clipboard
Type Narrowing doesnt work with match Statement
Consider the following code
import ballerina/io;
type UnaryExpr record {|
string operand;
|};
type TypeCastExpr record {|
string oprd;
|};
type Expr UnaryExpr|TypeCastExpr;
function foo(Expr expr) {
match expr {
var {oprd: o} => {
TypeCastExpr c = expr;
io:println(c);
}
}
}
public function main() {
Expr x = {oprd : "DFD"};
foo(x);
}
This code gives the following error.
incompatible types: expected 'TypeCastExpr', found 'Expr'