Skip to content

Commit 05f5189

Browse files
author
Elad Ben-Israel
authored
fix(jsii): deduplicate interfaces (#497)
When processing interfaces from multiple declaration sites (e.g. when a base class is erased), we need to make sure that only include every interface once. Fixes #496
1 parent 46bc9b0 commit 05f5189

File tree

17 files changed

+228
-7
lines changed

17 files changed

+228
-7
lines changed

packages/jsii-calc/lib/erasures.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ export interface IJsii487External { }
4848
export interface IJsii487External2 { }
4949
class Jsii487Internal implements IJsii487External { }
5050
export class Jsii487Derived extends Jsii487Internal implements IJsii487External2 { }
51+
52+
//
53+
// Deduplicate interfaces that come from different declaration sites
54+
// https://github.com/awslabs/jsii/issues/496
55+
//
56+
export interface IJsii496 { }
57+
class Jsii496Base implements IJsii496 { }
58+
export class Jsii496Derived extends Jsii496Base implements IJsii496 { }

packages/jsii-calc/test/assembly.jsii

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,16 @@
30553055
},
30563056
"name": "IJsii487External2"
30573057
},
3058+
"jsii-calc.IJsii496": {
3059+
"assembly": "jsii-calc",
3060+
"fqn": "jsii-calc.IJsii496",
3061+
"kind": "interface",
3062+
"locationInModule": {
3063+
"filename": "lib/erasures.ts",
3064+
"line": 56
3065+
},
3066+
"name": "IJsii496"
3067+
},
30583068
"jsii-calc.IMutableObjectLiteral": {
30593069
"assembly": "jsii-calc",
30603070
"fqn": "jsii-calc.IMutableObjectLiteral",
@@ -4073,6 +4083,20 @@
40734083
},
40744084
"name": "Jsii487Derived"
40754085
},
4086+
"jsii-calc.Jsii496Derived": {
4087+
"assembly": "jsii-calc",
4088+
"fqn": "jsii-calc.Jsii496Derived",
4089+
"initializer": {},
4090+
"interfaces": [
4091+
"jsii-calc.IJsii496"
4092+
],
4093+
"kind": "class",
4094+
"locationInModule": {
4095+
"filename": "lib/erasures.ts",
4096+
"line": 58
4097+
},
4098+
"name": "Jsii496Derived"
4099+
},
40764100
"jsii-calc.JsiiAgent": {
40774101
"assembly": "jsii-calc",
40784102
"docs": {
@@ -6779,5 +6803,5 @@
67796803
}
67806804
},
67816805
"version": "0.10.5",
6782-
"fingerprint": "yLgYMXLhffrmN5U4ftTmlWijmxvKaKHA4QXx9+adYe0="
6806+
"fingerprint": "Zn881YRFrX198/TaBpApis646FTCp/XbGmU7cWaw/cs="
67836807
}

packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,16 @@
30553055
},
30563056
"name": "IJsii487External2"
30573057
},
3058+
"jsii-calc.IJsii496": {
3059+
"assembly": "jsii-calc",
3060+
"fqn": "jsii-calc.IJsii496",
3061+
"kind": "interface",
3062+
"locationInModule": {
3063+
"filename": "lib/erasures.ts",
3064+
"line": 56
3065+
},
3066+
"name": "IJsii496"
3067+
},
30583068
"jsii-calc.IMutableObjectLiteral": {
30593069
"assembly": "jsii-calc",
30603070
"fqn": "jsii-calc.IMutableObjectLiteral",
@@ -4073,6 +4083,20 @@
40734083
},
40744084
"name": "Jsii487Derived"
40754085
},
4086+
"jsii-calc.Jsii496Derived": {
4087+
"assembly": "jsii-calc",
4088+
"fqn": "jsii-calc.Jsii496Derived",
4089+
"initializer": {},
4090+
"interfaces": [
4091+
"jsii-calc.IJsii496"
4092+
],
4093+
"kind": "class",
4094+
"locationInModule": {
4095+
"filename": "lib/erasures.ts",
4096+
"line": 58
4097+
},
4098+
"name": "Jsii496Derived"
4099+
},
40764100
"jsii-calc.JsiiAgent": {
40774101
"assembly": "jsii-calc",
40784102
"docs": {
@@ -6779,5 +6803,5 @@
67796803
}
67806804
},
67816805
"version": "0.10.5",
6782-
"fingerprint": "yLgYMXLhffrmN5U4ftTmlWijmxvKaKHA4QXx9+adYe0="
6806+
"fingerprint": "Zn881YRFrX198/TaBpApis646FTCp/XbGmU7cWaw/cs="
67836807
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
[JsiiInterface(nativeType: typeof(IIJsii496), fullyQualifiedName: "jsii-calc.IJsii496")]
6+
public interface IIJsii496
7+
{
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
[JsiiTypeProxy(nativeType: typeof(IIJsii496), fullyQualifiedName: "jsii-calc.IJsii496")]
6+
internal sealed class IJsii496Proxy : DeputyBase, IIJsii496
7+
{
8+
private IJsii496Proxy(ByRefValue reference): base(reference)
9+
{
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Amazon.JSII.Runtime.Deputy;
2+
3+
namespace Amazon.JSII.Tests.CalculatorNamespace
4+
{
5+
[JsiiClass(nativeType: typeof(Jsii496Derived), fullyQualifiedName: "jsii-calc.Jsii496Derived")]
6+
public class Jsii496Derived : DeputyBase, IIJsii496
7+
{
8+
public Jsii496Derived(): base(new DeputyProps(new object[]{}))
9+
{
10+
}
11+
12+
protected Jsii496Derived(ByRefValue reference): base(reference)
13+
{
14+
}
15+
16+
protected Jsii496Derived(DeputyProps props): base(props)
17+
{
18+
}
19+
}
20+
}

packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
6969
case "jsii-calc.IJSII417PublicBaseOfBase": return software.amazon.jsii.tests.calculator.IJSII417PublicBaseOfBase.class;
7070
case "jsii-calc.IJsii487External": return software.amazon.jsii.tests.calculator.IJsii487External.class;
7171
case "jsii-calc.IJsii487External2": return software.amazon.jsii.tests.calculator.IJsii487External2.class;
72+
case "jsii-calc.IJsii496": return software.amazon.jsii.tests.calculator.IJsii496.class;
7273
case "jsii-calc.IMutableObjectLiteral": return software.amazon.jsii.tests.calculator.IMutableObjectLiteral.class;
7374
case "jsii-calc.INonInternalInterface": return software.amazon.jsii.tests.calculator.INonInternalInterface.class;
7475
case "jsii-calc.IPrivatelyImplemented": return software.amazon.jsii.tests.calculator.IPrivatelyImplemented.class;
@@ -92,6 +93,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
9293
case "jsii-calc.JSObjectLiteralToNativeClass": return software.amazon.jsii.tests.calculator.JSObjectLiteralToNativeClass.class;
9394
case "jsii-calc.JavaReservedWords": return software.amazon.jsii.tests.calculator.JavaReservedWords.class;
9495
case "jsii-calc.Jsii487Derived": return software.amazon.jsii.tests.calculator.Jsii487Derived.class;
96+
case "jsii-calc.Jsii496Derived": return software.amazon.jsii.tests.calculator.Jsii496Derived.class;
9597
case "jsii-calc.JsiiAgent": return software.amazon.jsii.tests.calculator.JsiiAgent.class;
9698
case "jsii-calc.LoadBalancedFargateServiceProps": return software.amazon.jsii.tests.calculator.LoadBalancedFargateServiceProps.class;
9799
case "jsii-calc.Multiply": return software.amazon.jsii.tests.calculator.Multiply.class;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package software.amazon.jsii.tests.calculator;
2+
3+
@javax.annotation.Generated(value = "jsii-pacmak")
4+
public interface IJsii496 extends software.amazon.jsii.JsiiSerializable {
5+
6+
/**
7+
* A proxy class which represents a concrete javascript instance of this type.
8+
*/
9+
final static class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.IJsii496 {
10+
protected Jsii$Proxy(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
11+
super(mode);
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package software.amazon.jsii.tests.calculator;
2+
3+
@javax.annotation.Generated(value = "jsii-pacmak")
4+
@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.Jsii496Derived")
5+
public class Jsii496Derived extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.IJsii496 {
6+
protected Jsii496Derived(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
7+
super(mode);
8+
}
9+
public Jsii496Derived() {
10+
super(software.amazon.jsii.JsiiObject.InitializationMode.Jsii);
11+
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this);
12+
}
13+
}

packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,18 @@ class _IJsii487External2Proxy():
12981298
__jsii_type__ = "jsii-calc.IJsii487External2"
12991299
pass
13001300

1301+
@jsii.interface(jsii_type="jsii-calc.IJsii496")
1302+
class IJsii496(jsii.compat.Protocol):
1303+
@staticmethod
1304+
def __jsii_proxy_class__():
1305+
return _IJsii496Proxy
1306+
1307+
pass
1308+
1309+
class _IJsii496Proxy():
1310+
__jsii_type__ = "jsii-calc.IJsii496"
1311+
pass
1312+
13011313
@jsii.interface(jsii_type="jsii-calc.IMutableObjectLiteral")
13021314
class IMutableObjectLiteral(jsii.compat.Protocol):
13031315
@staticmethod
@@ -1985,6 +1997,12 @@ def __init__(self) -> None:
19851997
jsii.create(Jsii487Derived, self, [])
19861998

19871999

2000+
@jsii.implements(IJsii496)
2001+
class Jsii496Derived(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.Jsii496Derived"):
2002+
def __init__(self) -> None:
2003+
jsii.create(Jsii496Derived, self, [])
2004+
2005+
19882006
class JsiiAgent(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.JsiiAgent"):
19892007
"""Host runtime version should be set via JSII_AGENT."""
19902008
def __init__(self) -> None:
@@ -3302,6 +3320,6 @@ def parts(self, value: typing.List[scope.jsii_calc_lib.Value]):
33023320
return jsii.set(self, "parts", value)
33033321

33043322

3305-
__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DefaultedConstructorArgument", "DerivedClassHasNoProperties", "DerivedStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SingleInstanceTwoTypes", "StaticContext", "Statics", "StringEnum", "StripInternal", "Sum", "SyncVirtualMethods", "Thrower", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "__jsii_assembly__", "composition"]
3323+
__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AsyncVirtualMethods", "AugmentableClass", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithDocs", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumersOfThisCrazyTypeSystem", "DefaultedConstructorArgument", "DerivedClassHasNoProperties", "DerivedStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnotherPublicInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IJsii496", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnsNumber", "ImplementInternalInterface", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "Jsii496Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RuntimeTypeChecking", "SingleInstanceTwoTypes", "StaticContext", "Statics", "StringEnum", "StripInternal", "Sum", "SyncVirtualMethods", "Thrower", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "__jsii_assembly__", "composition"]
33063324

33073325
publication.publish()

0 commit comments

Comments
 (0)