Q:

How do I read an int from command line in Ballerina?

any choice = io:readln("Enter choice 1 - 5: ");

I cannot seem to cast the input to an int. 
Both check and match gives the same error 
var intChoice = <int>choice;
match intChoice {
    int value => c = value;
    error err => io:println("error: " + err.message);
}

and 
c = check <int>choice;

gives 
error: 'string' cannot be cast to 'int'

I looked into https://ballerina.io/learn/by-example/type-conversion.html and also studied https://ballerina.io/learn/api-docs/ballerina/io.html#readln but no luck. 
What am I doing wrong? 

A:

Seems like it is a bug in the any -> int conversion.
If you change the choice variable type to string or change the variable definition statement to assignment statement using var, both approaches will works. Please refer the below example.
import ballerina/io;

function main(string... args) {
    // Change the any to string or var here.
    string choice = io:readln("Enter choice 1 - 5: ");
    int c = check <int>choice;
    io:println(c);

    var intChoice = <int>choice;
    match intChoice {
        int value => io:println(value);
        error err => io:println("error: " + err.message);
    }
}

Update - As @supun has mentioned below, it is not a bug in any->int conversion, it is an implementation detail which I was not aware of.

