-
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 (…
- Loading branch information
Showing
4 changed files
with
152 additions
and
9 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
17 changes: 17 additions & 0 deletions
17
packages/jsii/test/negatives/neg.static-member-mixing.1.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,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 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/jsii/test/negatives/neg.static-member-mixing.2.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,11 @@ | ||
///!MATCH_ERROR: member 'funFunction' of class 'TheClass' cannot be declared both statically and non-statically | ||
|
||
export class TheClass { | ||
public static funFunction() { | ||
// Empty | ||
} | ||
|
||
public funFunction() { | ||
// Empty | ||
} | ||
} |