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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsii: Compiler allows class-inherited member to violate interface #3342

Closed
RomainMuller opened this issue Jan 17, 2022 · 1 comment 路 Fixed by #3343
Closed

jsii: Compiler allows class-inherited member to violate interface #3342

RomainMuller opened this issue Jan 17, 2022 · 1 comment 路 Fixed by #3343
Assignees
Labels
bug This issue is a bug. p1

Comments

@RomainMuller
Copy link
Contributor

馃悰 Bug Report

What is the problem?

The compiler does not check members inherited from a base class against the type's declared interfaces, and consequently allows the contract of said interface to be violated.

export interface IApplicationLoadBalancer {
  readonly vpc?: ec2.IVpc;
}


export class BaseLoadBalancer {
  readonly vpc: ec2.Vpc;
}

export class ApplicationLoadBalancer
  extends BaseLoadBalancer
  implements IApplicationLoadBalancer {
  // Inherits `vpc` from BaseLoadBalancer, but that is not optional,
  // when `IApplicationLoadBalancer` requires it to be optional.
}
@RomainMuller RomainMuller added bug This issue is a bug. p1 labels Jan 17, 2022
@RomainMuller RomainMuller self-assigned this Jan 17, 2022
RomainMuller pushed a commit to aws/aws-cdk that referenced this issue Jan 17, 2022
The `BaseLoadBalancer.vpc` property fulfills the `IApplicationLoadBalancer.vpc` and
`INetworkLoadBalancer.vpc` properties, both of which are optional. A bug in `jsii` (see aws/jsii#3342)
makes this pass type system consistency checks, when it should not be allowed.
mergify bot pushed a commit to aws/aws-cdk that referenced this issue Jan 18, 2022
The `BaseLoadBalancer.vpc` property fulfills the `IApplicationLoadBalancer.vpc` and
`INetworkLoadBalancer.vpc` properties, both of which are optional. A bug in `jsii` (see aws/jsii#3342)
makes this pass type system consistency checks, when it should not be allowed.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@mergify mergify bot closed this as completed in #3343 Jan 18, 2022
mergify bot pushed a commit that referenced this issue Jan 18, 2022
)

The compiler failed to check inherited members from a base class against
interfaces declared on the inheriting class, so that it was possible to
inherit members that changed the signature of the interface declarations
they implemented (typically specializing them: required implementations
of optional properties, etc...).

While this is valid TypeScript (the implementation is allowed to be
strictly more specific than the interface declaration), this is not
allowed by jsii as this results in type models that cannot be
represented in C# (and other languages that do not allow specialization
by implementing or overriding members).

In addition to fixing this issue, this change adds source bindings to
diagnostics generated when property implementations are rejected, and
fixes a logical error in the message for `JSII5010` (`immutable` and
`mutable` were reversed so the message read the wrong way around).

Fixes #3342 

---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
@github-actions
Copy link
Contributor

鈿狅笍COMMENT VISIBILITY WARNING鈿狅笍

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
The `BaseLoadBalancer.vpc` property fulfills the `IApplicationLoadBalancer.vpc` and
`INetworkLoadBalancer.vpc` properties, both of which are optional. A bug in `jsii` (see aws/jsii#3342)
makes this pass type system consistency checks, when it should not be allowed.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant