Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional field access on a union of record and map #17942

Closed
MaryamZi opened this issue Aug 18, 2019 · 1 comment
Closed

Optional field access on a union of record and map #17942

MaryamZi opened this issue Aug 18, 2019 · 1 comment
Assignees
Labels
Points/1 Equivalent to one day effort Priority/Low Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/NewFeature Type/SpecDeviation

Comments

@MaryamZi
Copy link
Member

Description:
The spec says for "Optional field access expression"

Let T be the static type of expression, let T' be the intersection of T and 
basic type mapping, let K be the singleton type containing just the 
string field-name and let M be the member type of K in T'. The compile-time 
requirements on the optional-field-access-expr depend on whether the 
type descriptor describing T is lax:

- if it is lax, then the only compile-time requirement is that M is non-empty;
- if it is not lax, then, in addition, T must be a subtype of the union of () and 
the mapping basic type, and the type descriptor for T must include field-name 
as an individual-type-descriptor (if the type descriptor is a union, then this 
requirement must be satisfied by at least one member of the union).

For point 2, currently we allow optional field access only on a union of records, if at lease one record has a field by the identifier. We don't allow the same, if at least one member is a map. Should we allow this?

Steps to reproduce:

import ballerina/io;

type Foo record {
    string s;
};

public function main(string... args) {
    Foo f = { s: "hello" };
    map<string>|Foo u = f;
    string? s = u?.s;
    io:println(s);
}

Affected Versions:
1.0.0-beta-SNAPSHOT - 15th August build

@MaryamZi MaryamZi added Type/SpecDeviation Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. labels Aug 18, 2019
@pubudu91 pubudu91 added this to the Ballerina 1.1.0 milestone Oct 18, 2019
@hasithaa hasithaa removed this from the Ballerina 1.1.0 milestone Dec 20, 2019
@rdhananjaya rdhananjaya added the Points/2 Equivalent to two days effort label Apr 2, 2020
@pubudu91 pubudu91 added this to the Ballerina 1.3.0 milestone Apr 16, 2020
@pubudu91 pubudu91 added Points/1 Equivalent to one day effort and removed Points/2 Equivalent to two days effort labels Apr 16, 2020
@MaryamZi
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Points/1 Equivalent to one day effort Priority/Low Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/NewFeature Type/SpecDeviation
Projects
None yet
Development

No branches or pull requests

6 participants