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]: Computed name field did not give run-time error for immutable type #40361

Open
prakanth97 opened this issue May 8, 2023 · 1 comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug

Comments

@prakanth97
Copy link
Contributor

Description

import ballerina/io;

const x = "a";
readonly X = {a : "A", [x] : "B"};

public function main() {
    io:println(X);
}

Currently it returns {"a":"B"}. But spec says,

A mapping-constructor-expr first constructs a mapping value without considering any computed-name-field. 
The effect of a computed-name-field is to modify the member of the mapping with the specified name after 
the mapping has been constructed. If the modification is incompatible with the inherent type, then the 
mapping-constructor-expr will panic. The modifications are performed in the order in which the computed-name-fields
 occur in the mapping-constructor-expr.

The modification should be panic for immutable types.

Steps to Reproduce

No response

Affected Version(s)

2201.5.0
Master

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

@prakanth97 prakanth97 added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. labels May 8, 2023
@MaryamZi
Copy link
Member

MaryamZi commented May 9, 2023

While the const scenario will be disallowed once ballerina-platform/ballerina-spec#772 is addressed, this also disallows the non-const case which is kinda too restrictive IMO.

Related to ballerina-platform/ballerina-spec#532.
Created ballerina-platform/ballerina-spec#1245.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Projects
None yet
Development

No branches or pull requests

2 participants