ballerina-platform / ballerina-lang

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

[Bug]: Type reference type information is not available for record values #43633

Open rdulmina opened 1 week ago

rdulmina commented 1 week ago

Description

Consider the below sample

type Foo2 record {|
    string s;
    *RefType;
    int i;
    *ClosedRefType;
|};

function testRefTypes() returns Foo2 {
    Foo2 f = {s:"qwerty", i:10, rx:xml `<book>Count of Monte Cristo</book>`, rp:new("John Doe"), crp:new("Jane Doe"), crx:xml `<book>Count of Monte Cristo</book>`};
    json j = {name: "apple", color: "red", price: 40};
    Address adr = {city:"Colombo", country:"Sri Lanka"};

    f.rj = j;
    f.ra = adr;
    f.crj = j;
    f.cra = adr;

    return f;
}

When we get the type of the return value, it is BRecordType. This should Ideally be BTypeReferenceType

Screenshot 2024-11-21 at 11 18 03

Steps to Reproduce

No response

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

MaryamZi commented 1 week ago

I believe we always set a mapping type (map type or record type) to mapping values.

This is somewhat similar to what we had at compile-time before your changes to persist the type reference type in the frontend even with expressions.

This may not be incorrect either. Note that in the spec, the type-reference type-descriptor is only for an alias - see https://ballerina.io/spec/lang/master/#type-reference. So what we get with typeof (which is effectively what you're doing here), being a record seems okay.