-
Notifications
You must be signed in to change notification settings - Fork 755
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
Type included object's functions have to have the same parameter names #42667
Comments
In Ballerina compiler function argument is represented a combination of argument type and the argument name (In java it is only type). Following is a valid use case that used the argument name.
In the above code we support |
I'm not sure if the current restriction is required in the spec, I've created a spec issue for this.
Parameter names don't affect typing. The argument list is always constructed at the call site and is based on the import ballerina/io;
type Data record {|int a; string c; boolean b;|};
function foo(int x, string y, boolean z) {
io:println("x: ", x);
io:println("y: ", y);
io:println("z: ", z);
}
public function main() {
Data data = {a: 1, c: "hello", b: true};
// Allowed since parameter names don't affect typing.
function (int a, string c, boolean b) fn = foo;
// Argument list is constructed as
// `(1, "hello", true)` in `fn(1, "hello", true)`
fn(...data);
// Disallowed since parameter types don't match by position,
// irrespective of names.
// error: expected 'function (string,int,boolean) returns ()',
// found 'function (int,string,boolean) returns ()'
// function (string y, int x, boolean z) _ = foo;
} x: 1
y: hello
z: true |
We can get rid of this restriction - ballerina-platform/ballerina-spec#1304 |
Description
See the below object type;
when I type included this in another object and changed the name of a parameter like below;
Ballerina complains saying;
Steps to Reproduce
No response
Affected Version(s)
Ballerina 2201.8.4 (Swan Lake Update 8)
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
The text was updated successfully, but these errors were encountered: