ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.6k stars 745 forks source link

Arithmetic operators are allowed with some union types #35749

Open rdulmina opened 2 years ago

rdulmina commented 2 years ago

Description:

The below invalid sample compiles runs and gives the correct output

public function main() {
    float|decimal a = 44.3d;
    float b = 2;
    float c = a * b; // 88.6
}

However, if we interchange the order of union it will fail at compile time

public function main() {
    decimal|float a = 44.3d;
    float b = 2;
    float c = a * b; // error operator '*' not defined for '(decimal|float)' and 'float'
}
MaryamZi commented 1 year ago

Result in a compilation error on Swan Lake Update 1 and later versions. Keeping the issue open to add tests.