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

Parameter type of clone and cloneReadOnly #531

Closed
irshadnilam opened this issue May 26, 2020 · 5 comments
Closed

Parameter type of clone and cloneReadOnly #531

irshadnilam opened this issue May 26, 2020 · 5 comments
Assignees
Labels
Area/Lang Relates to the Ballerina language specification spec/incorrect Mistake in spec affecting substance

Comments

@irshadnilam
Copy link

Description:
There is a requirement to use an existing array of errors in the detail record of an error.

Since error[] does not match with anydata (#463), this has to match with readonly.

While we can create an readonly array:

error[] & readonly x = [e1, e2];

There is not a way to create a readonly copy of an existing array of errors.
This cloneReadOnly params are of anydata|readonly.

Do we need to provide a mechanism to support this?

@jclark jclark changed the title Getting a readonly clone of an existing array of errors. Parameter type of clone and cloneReadOnly May 29, 2020
@jclark jclark self-assigned this May 29, 2020
@jclark jclark added the Area/Lang Relates to the Ballerina language specification label May 29, 2020
@jclark jclark added this to the 2020R2 milestone May 29, 2020
@jclark jclark added the spec/incorrect Mistake in spec affecting substance label May 29, 2020
@jclark
Copy link
Collaborator

jclark commented May 29, 2020

The argument type of clone and cloneReadOnly are wrong. Instead of:

@typeParam
type CloneableType anydata|readonly;
public function clone(CloneableType v) returns CloneableType = external;
public function cloneReadOnly(CloneableType v) returns CloneableType = external;

we should have:

type Cloneable readonly|xml|Cloneable[]|map<Cloneable>|table<map<Cloneable>>;
@typeParam
type CloneableType Cloneable;
public function clone(CloneableType v) returns CloneableType = external;
public function cloneReadOnly(CloneableType v) returns CloneableType & readonly = external;

@jclark
Copy link
Collaborator

jclark commented Jun 17, 2020

@hasithaa Note that this also needs to apply to other places where the spec used anydata|readonly, in particular:

  • error detail record
  • message send
  • annotations

Since it is generally useful, I made it public in lang.value.

@KRVPerera
Copy link
Contributor

Please help clarify. Current spec is updated as below.

public function cloneReadOnly(CloneableType v) returns CloneableType = external;

Shouldn't this be changed to

public function cloneReadOnly(CloneableType v) returns CloneableType & readonly = external;

@jclark
Copy link
Collaborator

jclark commented Jul 15, 2020

Yes, it should be changed

@jclark jclark reopened this Jul 15, 2020
@jclark jclark closed this as completed in 17d054b Jul 15, 2020
@KRVPerera
Copy link
Contributor

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification spec/incorrect Mistake in spec affecting substance
Projects
None yet
Development

No branches or pull requests

4 participants