-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jsii): detect changing visibility when overriding (#1876)
Since C# does not allow changing the visibility of a member when overriding it, added a check to ensure nobody attempts to make a protected member public when overriding it. This is a somewhat common pitfall for users (as seen for example in aws/aws-cdk#9616), and the check will allow faster detection and correction (i.e: at compilation time instead of during `jsii-pacmak`).
- Loading branch information
1 parent
42a9823
commit cfc99c2
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
packages/jsii/test/negatives/neg.override-changes-visibility.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Note: not testing "public -> protected" because this is invalid TypeScript, | ||
// so the type checker will already have caught it for us. | ||
|
||
export class BaseClass { | ||
protected readonly property?: string; | ||
|
||
protected method() { | ||
return; | ||
} | ||
} | ||
|
||
export class ChildClass extends BaseClass { | ||
// This property cannot be public as it overrides the one on BaseClass which is protected | ||
public readonly property?: string; | ||
|
||
// This method cannot be public as it overrides the one on BaseClass which is protected | ||
public method() { | ||
throw new Error('Not Implemented'); | ||
} | ||
} |