Description
When a match statement's subject expression has a type that includes error (e.g. JSON field access j.kind which produces json|error), the var _ wildcard binding pattern never matches at runtime even when it should.
Steps to Reproduce
- Create a Ballerina file with the following code:
import ballerina/io;
function getKind(json j) returns string {
match j.kind {
"a" => {
return "A";
}
error(var _) => {
return "E";
}
var _ => {
return "B";
}
}
}
public function main() {
json myData = {kind: "b"};
string result = getKind(myData);
io:println("Returned value: ", result);
}
- Observe the output:
Expected: Returned value: B
The var _ clause should match "b" since it is a non-error json value.
Affected Version(s)
No response
OS, DB, other environment details and versions
No response
Related area
-> Compilation
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
Description
When a match statement's subject expression has a type that includes error (e.g. JSON field access j.kind which produces json|error), the var _ wildcard binding pattern never matches at runtime even when it should.
Steps to Reproduce
Expected: Returned value: B
The var _ clause should match "b" since it is a non-error json value.
Affected Version(s)
No response
OS, DB, other environment details and versions
No response
Related area
-> Compilation
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response