Skip to content

Commit

Permalink
fix: copy non-hidden bases when erasing hidden interfaces (#392)
Browse files Browse the repository at this point in the history
When a type inherits (extends/implements) from a hidden (private/internal)
interface, and that interface extends a non-hidden interface, we need to 
copy the non-hidden interface to the consuming type so that it can be polymorphically
used.

Follow up on #390

Co-authored-by: RomainMuller <rmuller@amazon.com>
  • Loading branch information
Elad Ben-Israel and RomainMuller authored Mar 19, 2019
1 parent e232cb5 commit 5af84b6
Show file tree
Hide file tree
Showing 26 changed files with 1,163 additions and 63 deletions.
52 changes: 52 additions & 0 deletions packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1424,3 +1424,55 @@ export class ImplementsPrivateInterface implements IPrivateInterface {
export interface ExtendsPrivateInterface extends IPrivateInterface {
moreThings: string[];
}

//
// hidden (private/internal) base interface erasure will copy non-hidden bases from
// hidden to consuming type.
//

export interface IAnotherPublicInterface {
a: string;

}

/** @internal */
export interface IAnotherInternalInterface extends IAnotherPublicInterface {
b: string;
}

export interface INonInternalInterface extends IAnotherInternalInterface {
c: string;
}

/** @internal */
export interface IInternalInterfaceThatExtendsTheNonInternalOne extends INonInternalInterface {
d: string;
}

interface IPrivateInterfaceThatExtendsTheNonInternalOne extends INonInternalInterface {
e: string;
}

export class ClassThatImplementsTheInternalInterface implements IInternalInterfaceThatExtendsTheNonInternalOne, INonInternalInterface {
public a = 'a';
public b = 'b';
public c = 'c';
public d = 'd';
}

export class ClassThatImplementsThePrivateInterface implements IPrivateInterfaceThatExtendsTheNonInternalOne {
public a = 'a';
public b = 'b';
public c = 'c';
public e = 'e';
}

export class ConsumersOfThisCrazyTypeSystem {
public consumeAnotherPublicInterface(obj: IAnotherPublicInterface) {
return obj.a;
}

public consumeNonInternalInterface(obj: INonInternalInterface): any {
return { a: obj.a, b: obj.b, c: obj.c };
}
}
168 changes: 167 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,98 @@
}
]
},
"jsii-calc.ClassThatImplementsTheInternalInterface": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.ClassThatImplementsTheInternalInterface",
"initializer": {
"initializer": true
},
"interfaces": [
{
"fqn": "jsii-calc.INonInternalInterface"
}
],
"kind": "class",
"name": "ClassThatImplementsTheInternalInterface",
"properties": [
{
"name": "a",
"overrides": {
"fqn": "jsii-calc.IAnotherPublicInterface"
},
"type": {
"primitive": "string"
}
},
{
"name": "b",
"type": {
"primitive": "string"
}
},
{
"name": "c",
"overrides": {
"fqn": "jsii-calc.INonInternalInterface"
},
"type": {
"primitive": "string"
}
},
{
"name": "d",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.ClassThatImplementsThePrivateInterface": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.ClassThatImplementsThePrivateInterface",
"initializer": {
"initializer": true
},
"interfaces": [
{
"fqn": "jsii-calc.INonInternalInterface"
}
],
"kind": "class",
"name": "ClassThatImplementsThePrivateInterface",
"properties": [
{
"name": "a",
"overrides": {
"fqn": "jsii-calc.IAnotherPublicInterface"
},
"type": {
"primitive": "string"
}
},
{
"name": "b",
"type": {
"primitive": "string"
}
},
{
"name": "c",
"overrides": {
"fqn": "jsii-calc.INonInternalInterface"
},
"type": {
"primitive": "string"
}
},
{
"name": "e",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.ClassWithMutableObjectLiteralProperty": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.ClassWithMutableObjectLiteralProperty",
Expand Down Expand Up @@ -1140,6 +1232,45 @@
],
"name": "Constructors"
},
"jsii-calc.ConsumersOfThisCrazyTypeSystem": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.ConsumersOfThisCrazyTypeSystem",
"initializer": {
"initializer": true
},
"kind": "class",
"methods": [
{
"name": "consumeAnotherPublicInterface",
"parameters": [
{
"name": "obj",
"type": {
"fqn": "jsii-calc.IAnotherPublicInterface"
}
}
],
"returns": {
"primitive": "string"
}
},
{
"name": "consumeNonInternalInterface",
"parameters": [
{
"name": "obj",
"type": {
"fqn": "jsii-calc.INonInternalInterface"
}
}
],
"returns": {
"primitive": "any"
}
}
],
"name": "ConsumersOfThisCrazyTypeSystem"
},
"jsii-calc.DefaultedConstructorArgument": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.DefaultedConstructorArgument",
Expand Down Expand Up @@ -1611,6 +1742,21 @@
],
"name": "GreetingAugmenter"
},
"jsii-calc.IAnotherPublicInterface": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IAnotherPublicInterface",
"kind": "interface",
"name": "IAnotherPublicInterface",
"properties": [
{
"abstract": true,
"name": "a",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IFriendlier": {
"assembly": "jsii-calc",
"docs": {
Expand Down Expand Up @@ -1750,6 +1896,26 @@
],
"name": "IInterfaceWithOptionalMethodArguments"
},
"jsii-calc.INonInternalInterface": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.INonInternalInterface",
"interfaces": [
{
"fqn": "jsii-calc.IAnotherPublicInterface"
}
],
"kind": "interface",
"name": "INonInternalInterface",
"properties": [
{
"abstract": true,
"name": "c",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IPrivatelyImplemented": {
"assembly": "jsii-calc",
"fqn": "jsii-calc.IPrivatelyImplemented",
Expand Down Expand Up @@ -4083,5 +4249,5 @@
}
},
"version": "0.7.15",
"fingerprint": "iMxRj3lsHKNzSiBrjCyBH6Pp7Uvo+1Sxh/jN3hW+3nA="
"fingerprint": "y7h6OQBzbQrvU43LHTizXl12OUAEOpXhqD02OJfmhWQ="
}
Loading

0 comments on commit 5af84b6

Please sign in to comment.