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

Should methods of including objects have the same parameter names as those of an included object? #1304

Closed
MaryamZi opened this issue May 20, 2024 · 2 comments
Assignees

Comments

@MaryamZi
Copy link
Member

Description:
jBallerina currently disallows the following since the name of the parameter is different.

type Config object {
    function get(string k) returns anydata;
};

class ConfigImpl {
    *Config;

    function get(string key) returns anydata { // `key` instead of `k` as parameter name

    }
}

But I'm not sure if the spec requires this? (These may be due to checks left over from an older implementation).

The spec only says

A type-reference to a class is treated as a reference to the class's type; only the types of the methods and fields are copied from the referenced type. An object-field-descriptor or method-decl in a object-type-descriptor can override respectively an object-field-descriptor or method-decl of the same name in an included object-type-descriptor, provided the type declared for the field or method in the overriding descriptor is a subtype of the type declared in the overridden descriptor. An object-field-descriptor cannot override a method-decl, nor can a method-decl override an object-field-descriptor. It is an error if an object-type-descriptor has two or more object-type-inclusions that include an object-field-descriptor with the same name, unless those object-field-descriptors are overridden by an object-field-descriptor in the including object-type-descriptor. It is an error if an object-type-descriptor has two or more object-type-inclusions that include method-decls with the same name but different function-signatures, unless those method-decls are overridden by a method-decl in the including object-type-descriptor.

In general, of course we do not consider the names of parameters for typing, and this particular case is disallowed via an additional check for object type inclusion.

The following are allowed (as expected).

type Config record {
    function (string k) returns anydata get;
};

type ConfigImpl record {
    *Config;
    // overrding like this is allowed since it is a subtype of `get` from `Config`
    function (string key) returns anydata get;
};
function get(string key) returns anydata {

}

function (string k) returns anydata getFunc = get;

Related issues:

@jclark
Copy link
Collaborator

jclark commented May 30, 2024

I don't think the spec requires the parameter names to be the same.

@MaryamZi
Copy link
Member Author

MaryamZi commented Jul 8, 2024

Thank you, we will get rid of this restriction in jBallerina.

@MaryamZi MaryamZi closed this as completed Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants