ballerina-lang
ballerina-lang copied to clipboard
Unnecessary calls to `TypeChecker.checkCast` for compile time know subtypes
trafficstars
Consider the following code.
const OFF = 0;
type Color "red" | "green" | "blue" | OFF;
function parseColor(string c) returns Color {
if c is "r" {
return "red";
}
else if c is "g" {
return "green";
}
else if c is "b" {
return "blue";
}
else if c is "0" {
return OFF;
}
panic error("unexpected input : " + c);
}
In this there is no need to check each given constant (eg "red") is a subtype of Color since it's known at compile time.