-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jsii): check that static and nonstatic members don't share a name
This is not allowed in Java, and leads to compiler warnings in C#. Fixes #427.
- Loading branch information
Rico Huijbers
committed
Apr 4, 2019
1 parent
afbabff
commit 308e887
Showing
3 changed files
with
124 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Statics | ||
|
||
## Constraints | ||
|
||
### TypeScript | ||
|
||
Static and non-static members live in completely different namespaces. Statics only exist on the class, | ||
and cannot be accessed through the class. | ||
|
||
Hence, it is perfectly fine to have a static and a non-static with the same name. | ||
|
||
Superclass statics can be accessed through subclasses, and they can be overridden by subclasses. | ||
|
||
### Java | ||
|
||
Statics and non-statics share a namespace. There cannot be a static and a | ||
nonstatic with the same name on the same class. The same holds for inherited | ||
members; a non-static in a superclass prevents a static of the same name in a | ||
subclass, same for a static in a superclass and a nonstatic in a subclass. | ||
|
||
Superclass statics can be accessed through subclasses, and even through | ||
instances and subclass instances. | ||
|
||
Statics can be overridden, though they do not participate in polymorphism. | ||
|
||
### C# | ||
|
||
Does not allow static and nonstatic members with the same name on the same class. | ||
|
||
**Will** allow static and nonstatic members of the same name on subclasses, | ||
but will issue a compiler warning that the user probably intended to use the | ||
`new` keyword to unambiguously introduce a new symbol. | ||
|
||
**Will** allow overriding of statics on a subclass, but will issue a warning | ||
about the `new` keyword again. | ||
|
||
## Rules | ||
|
||
In order to accomodate Java, we disallow any inherited members to conflict on | ||
staticness. |
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
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,17 @@ | ||
///!MATCH_ERROR: non-static member 'funFunction' of class 'Sub' conflicts with static member in ancestor 'SuperDuper' | ||
|
||
export class SuperDuper { | ||
public static funFunction() { | ||
// Empty | ||
} | ||
} | ||
|
||
export class Super extends SuperDuper { | ||
// Empty | ||
} | ||
|
||
export class Sub extends Super { | ||
public funFunction() { | ||
// Oops | ||
} | ||
} |