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

Disallow argument mismatch between interface and implementation #1320

Open
iliapolo opened this issue Sep 9, 2024 · 1 comment
Open

Disallow argument mismatch between interface and implementation #1320

iliapolo opened this issue Sep 9, 2024 · 1 comment

Comments

@iliapolo
Copy link
Contributor

iliapolo commented Sep 9, 2024

Currently, the compiler will allow the following program:

export interface IAdder {
  add(a: number, b: number): number;
}

export class Adder implements IAdder {
  public add(a1: number, b1: number): number {
    return a1 + b1;
  }
}

Notice the argument names in Adder.add are different from IAdder.add.

This results in an incompatibility between the IAdder interface and the Adder class in python. See:

We should have the compiler enforce that functions in implementations (or subclasses) use the same argument names as the parent.

Notes

  • Unless we roll out a new major version, we cannot start enforcing this on existing projects because the fix would have to be argument renaming, and this would be a breaking change. In order to maintain backwards compatibility and stop the proliferation of this mistake, we need to provide an allow list mechanism to ignore existing violations, as well as a feature toggle to activate this validation. In the next major version of the compiler, we can remove these provisions and start enforcing it.
  • It would be nice to resurrect and merge fix(jsii-diff): renaming a positional argument is a breaking change in Python jsii#2937 as well, as this would protect us against accidental renaming, either in an attempt to fix the inconsistency, or just an ad-hoc decision to rename some arguments.
@iliapolo
Copy link
Contributor Author

iliapolo commented Sep 9, 2024

We should only pick this up after a decision has been made with respect to aws/jsii#4541 (comment)

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

1 participant