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]: A variable declared as an explicit readonly record does not include a reference type as one of its constituent types #41912

Closed
Dilhasha opened this issue Dec 20, 2023 · 3 comments
Labels
Reason/Invalid Issue is invalid. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug

Comments

@Dilhasha
Copy link
Contributor

Description

$subject.

Steps to Reproduce

Consider the below code snippet.

public type ReadOnlyRecord readonly & record {
    string readOnlyValue;
};

public type NormalRecord record {
    string normalValue;
};

configurable ReadOnlyRecord record1 = ?;
configurable NormalRecord record2 = ?;

The constituent types of record2 has reference type.
But, record1 does not have reference type.

Affected Version(s)

2201.8.4

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

#41906

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Dec 20, 2023
@Dilhasha Dilhasha added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. and removed needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Dec 20, 2023
@MaryamZi
Copy link
Member

Looping in @HindujaB, since this is an issue specific to configurable variables.

Is your expectation to get readonly and ReadOnlyRecord as constituent types? The current behaviour may be because ReadOnlyRecord is already readonly.

The spec requirements is

The static type of a variable declared as configurable is implicitly readonly: the type specified in the type-descriptor is intersected with readonly.

So IMO, we don't really have to create an intersection type that is readonly & ReadOnlyRecord for record1, which is effectively readonly & (readonly & record { string readOnlyValue; }).

Also note that even if you did get readonly and ReadOnlyRecord as constituent types, ReadOnlyRecord will be an intersection type where one of it's constituent types will be an anonymous record type. The behaviour won't be the same as for NormalRecord, since with

public type NormalRecord record {
    string normalValue;
};

the name NormalRecord is specified for the record, whereas with

public type ReadOnlyRecord readonly & record {
    string readOnlyValue;
};

the name is for the intersection type.

@HindujaB
Copy link
Contributor

I agree with the comment from @MaryamZi. We can't depend on the getConstituentTypes() to return a type-reference type for the first element. It can vary depending on the record descriptor. At runtime, we use a recursive method called getImpliedType() to extract the underlying record type.
There is a relevant compiler FE API, which we can use.


(Need to move this API to a proper class.)
And, we may need to check the anonymous flags to identify the record name.

@Dilhasha
Copy link
Contributor Author

Agree with the comments. We'll check on a proper implementation for the initial requirement.

@Dilhasha Dilhasha added the Reason/Invalid Issue is invalid. label Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reason/Invalid Issue is invalid. 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

4 participants