user272735
user272735

Reputation: 10648

Error type unexpectedly involved in table query construction

I'm trying to build a table with a query expression as mentioned in create tables with query but I keep running into issue:

ERROR incompatible types: expected 'table<Foo> key(a)', found '(table<Foo> key(a)|error)'

It's easy to work around e.g.:

table<Foo> key(a)|error x = ...

or

check table key(a) ...

But what bothers me here is that I fail to find any explanation from the documentation why an error is involved here when in list comprehension it's not as the following compiles and runs just fine:

Foo[] x = from int i in 0...9 select {a:i, b:0};

The complete example:

$ cat issue.bal 
import ballerina/io;

type Foo record {|
    readonly int a;
    int b;
|};

public function main() {
    table<Foo> key(a) x = 
        table key(a)
        from int i in 0...9
        select {a:i, b:0}
    ;

    io:println(x);
}
$ bal run issue.bal
Compiling source
    issue.bal
ERROR [issue.bal:(10:9,12:31)] incompatible types: expected 'table<Foo> key(a)', found '(table<Foo> key(a)|error)'
error: compilation contains errors

I'm using:

$ bal version
Ballerina 2201.1.0 (Swan Lake Update 1)
Language specification 2022R2
Update Tool 1.3.9

Upvotes: 1

Views: 171

Answers (1)

Chiran Fernando
Chiran Fernando

Reputation: 437

This is actually a bug that was tracked with https://github.com/ballerina-platform/ballerina-lang/issues/36686 and fixed. The fix will be made available with the 2201.2.0 release, which will be released soon.

Upvotes: 2

Related Questions