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

[Bug]: No error when a spread field is used with an open record to construct a closed record #41740

Closed
MaryamZi opened this issue Nov 21, 2023 · 1 comment · Fixed by #41784
Closed
Assignees
Labels
Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Milestone

Comments

@MaryamZi
Copy link
Member

Description

$title, panics at runtime instead.

If there is a contextually expected type, then the type that the inherent type requires for each field provides the contextually expected type for the value-expr in a field; otherwise there is no contextually expected type for the value-expr for fields. If there is a contextually expected type, the contextually expected type for the expression in a spread-field is map<T>, where the T is the smallest type such that the inherent type is a subtype of map<T>. The contextually expected type for a field-name-expr is string.

Steps to Reproduce

type Address record {
    string street;
};

public function main() {
    Address address = {street: "Main Street", "number": 40};
    record {|string street;|} _ = {...address}; // no compilation error
}
error: {ballerina/lang.map}KeyNotFound {"message":"invalid field access: field 'number' not found in record type 'record {| string street; |}'"}
        at sample:main(sample.bal:7)

Affected Version(s)

2201.8.0

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

Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@poorna2152 poorna2152 added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Feb 27, 2024
@poorna2152 poorna2152 added this to the 2201.9.0 milestone Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Projects
None yet
2 participants