diff --git a/packages/jsii-calc/lib/compliance.ts b/packages/jsii-calc/lib/compliance.ts index d7c865f321..1fc7fbae84 100644 --- a/packages/jsii-calc/lib/compliance.ts +++ b/packages/jsii-calc/lib/compliance.ts @@ -2236,3 +2236,33 @@ export class SomeTypeJsii976 { return new Derived(); } } + +/** https://github.com/aws/jsii/issues/982 */ +export interface ParentStruct982 { + readonly foo: string; +} +export interface ChildStruct982 extends ParentStruct982 { + readonly bar: number; +} +/** + * 1. call #takeThis() -> An ObjectRef will be provisioned for the value (it'll be re-used!) + * 2. call #takeThisToo() -> The ObjectRef from before will need to be down-cased to the ParentStruct982 type + */ +export class Demonstrate982 { + private static readonly value = { + foo: 'foo', + bar: 1337, + }; + + /** It's dangerous to go alone! */ + public static takeThis(): ChildStruct982 { + return this.value; + } + + /** It's dangerous to go alone! */ + public static takeThisToo(): ParentStruct982 { + return this.value; + } + + public constructor() { } +} diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index e373ae6f10..67ae620bac 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -1678,6 +1678,40 @@ } ] }, + "jsii-calc.ChildStruct982": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "experimental" + }, + "fqn": "jsii-calc.ChildStruct982", + "interfaces": [ + "jsii-calc.ParentStruct982" + ], + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2244 + }, + "name": "ChildStruct982", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "experimental" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2245 + }, + "name": "bar", + "type": { + "primitive": "number" + } + } + ] + }, "jsii-calc.ClassThatImplementsTheInternalInterface": { "assembly": "jsii-calc", "docs": { @@ -2825,6 +2859,62 @@ } ] }, + "jsii-calc.Demonstrate982": { + "assembly": "jsii-calc", + "docs": { + "remarks": "call #takeThis() -> An ObjectRef will be provisioned for the value (it'll be re-used!)\n2. call #takeThisToo() -> The ObjectRef from before will need to be down-cased to the ParentStruct982 type", + "stability": "experimental", + "summary": "1." + }, + "fqn": "jsii-calc.Demonstrate982", + "initializer": { + "docs": { + "stability": "experimental" + } + }, + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2251 + }, + "methods": [ + { + "docs": { + "stability": "experimental", + "summary": "It's dangerous to go alone!" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2258 + }, + "name": "takeThis", + "returns": { + "type": { + "fqn": "jsii-calc.ChildStruct982" + } + }, + "static": true + }, + { + "docs": { + "stability": "experimental", + "summary": "It's dangerous to go alone!" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2263 + }, + "name": "takeThisToo", + "returns": { + "type": { + "fqn": "jsii-calc.ParentStruct982" + } + }, + "static": true + } + ], + "name": "Demonstrate982" + }, "jsii-calc.DeprecatedClass": { "assembly": "jsii-calc", "docs": { @@ -7649,6 +7739,38 @@ ], "name": "OverrideReturnsObject" }, + "jsii-calc.ParentStruct982": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "experimental", + "summary": "https://github.com/aws/jsii/issues/982." + }, + "fqn": "jsii-calc.ParentStruct982", + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2241 + }, + "name": "ParentStruct982", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "experimental" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2242 + }, + "name": "foo", + "type": { + "primitive": "string" + } + } + ] + }, "jsii-calc.PartiallyInitializedThisConsumer": { "abstract": true, "assembly": "jsii-calc", @@ -11006,5 +11128,5 @@ } }, "version": "0.20.3", - "fingerprint": "umMeNAH41pX11GUAjHkw6RTyAwGCeTqRNJ2vPv5aeM0=" + "fingerprint": "cb2xJuwu7eu9+ulwYnbZUyzYyE3IkL5fCM4b8Gqr7Vo=" } diff --git a/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/Amazon.JSII.Runtime.IntegrationTests.csproj b/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/Amazon.JSII.Runtime.IntegrationTests.csproj index 14df2b9791..d80703157c 100644 --- a/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/Amazon.JSII.Runtime.IntegrationTests.csproj +++ b/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/Amazon.JSII.Runtime.IntegrationTests.csproj @@ -19,4 +19,8 @@ + + + + diff --git a/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs b/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs index 2c6b9dff3c..767ead2976 100644 --- a/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs +++ b/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs @@ -1258,5 +1258,12 @@ public double Next() return next; } } + + [Fact(DisplayName = Prefix + nameof(StructsCanBeDowncastedToParentType))] + public void StructsCanBeDowncastedToParentType() + { + Assert.NotNull(Demonstrate982.TakeThis()); + Assert.NotNull(Demonstrate982.TakeThisToo()); + } } } diff --git a/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/DeputyBase.cs b/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/DeputyBase.cs index 2d9eca424a..30013ddaae 100644 --- a/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/DeputyBase.cs +++ b/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/DeputyBase.cs @@ -455,12 +455,12 @@ private static JsiiMethodAttribute GetMethodAttributeCore(System.Type type, stri private IDictionary Proxies { get; } = new Dictionary(); - public TypeCode GetTypeCode() + TypeCode IConvertible.GetTypeCode() { return TypeCode.Object; } - public object ToType(System.Type conversionType, IFormatProvider provider) + object IConvertible.ToType(System.Type conversionType, IFormatProvider provider) { if (Proxies.ContainsKey(conversionType)) { @@ -498,14 +498,15 @@ bool ToTypeCore(out object result) return false; } - if (!Reference.Interfaces.Contains(interfaceAttribute.FullyQualifiedName)) + var types = ServiceContainer.ServiceProvider.GetRequiredService(); + + if (!TryFindSupportedInterface(interfaceAttribute.FullyQualifiedName, Reference.Interfaces, types, out var adequateFqn)) { // We can only convert to interfaces declared by this Reference result = null; return false; } - - var types = ServiceContainer.ServiceProvider.GetRequiredService(); + var proxyType = types.GetProxyType(interfaceAttribute.FullyQualifiedName); var constructorInfo = proxyType.GetConstructor( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, @@ -520,82 +521,100 @@ bool ToTypeCore(out object result) result = constructorInfo.Invoke(new object[]{ Reference.ForProxy() }); return true; + + bool TryFindSupportedInterface(string declaredFqn, string[] availableFqns, ITypeCache types, out string foundFqn) + { + var declaredType = types.GetInterfaceType(declaredFqn); + + foreach (var candidate in availableFqns) + { + var candidateType = types.GetInterfaceType(candidate); + if (declaredType.IsAssignableFrom(candidateType)) + { + foundFqn = candidate; + return true; + } + } + + foundFqn = null; + return false; + } } } #region Impossible Conversions - public bool ToBoolean(IFormatProvider provider) + bool IConvertible.ToBoolean(IFormatProvider provider) { throw new InvalidCastException(); } - public byte ToByte(IFormatProvider provider) + byte IConvertible.ToByte(IFormatProvider provider) { throw new InvalidCastException(); } - public char ToChar(IFormatProvider provider) + char IConvertible.ToChar(IFormatProvider provider) { throw new InvalidCastException(); } - public DateTime ToDateTime(IFormatProvider provider) + DateTime IConvertible.ToDateTime(IFormatProvider provider) { throw new InvalidCastException(); } - public decimal ToDecimal(IFormatProvider provider) + decimal IConvertible.ToDecimal(IFormatProvider provider) { throw new InvalidCastException(); } - public double ToDouble(IFormatProvider provider) + double IConvertible.ToDouble(IFormatProvider provider) { throw new InvalidCastException(); } - public short ToInt16(IFormatProvider provider) + short IConvertible.ToInt16(IFormatProvider provider) { throw new InvalidCastException(); } - public int ToInt32(IFormatProvider provider) + int IConvertible.ToInt32(IFormatProvider provider) { throw new InvalidCastException(); } - public long ToInt64(IFormatProvider provider) + long IConvertible.ToInt64(IFormatProvider provider) { throw new InvalidCastException(); } - public sbyte ToSByte(IFormatProvider provider) + sbyte IConvertible.ToSByte(IFormatProvider provider) { throw new InvalidCastException(); } - public float ToSingle(IFormatProvider provider) + float IConvertible.ToSingle(IFormatProvider provider) { throw new InvalidCastException(); } - public string ToString(IFormatProvider provider) + string IConvertible.ToString(IFormatProvider provider) { throw new InvalidCastException(); } - public ushort ToUInt16(IFormatProvider provider) + ushort IConvertible.ToUInt16(IFormatProvider provider) { throw new InvalidCastException(); } - public uint ToUInt32(IFormatProvider provider) + uint IConvertible.ToUInt32(IFormatProvider provider) { throw new InvalidCastException(); } - public ulong ToUInt64(IFormatProvider provider) + ulong IConvertible.ToUInt64(IFormatProvider provider) { throw new InvalidCastException(); } diff --git a/packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java b/packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java index 45d8ca4ff8..7ae6aab952 100644 --- a/packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java +++ b/packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java @@ -1397,6 +1397,12 @@ public void returnSubclassThatImplementsInterface976() { assertEquals(obj.getFoo(), 333); } + @Test + public void testStructsCanBeDowncastedToParentType() { + assertNotNull(Demonstrate982.takeThis()); + assertNotNull(Demonstrate982.takeThisToo()); + } + static class PartiallyInitializedThisConsumerImpl extends PartiallyInitializedThisConsumer { @Override public String consumePartiallyInitializedThis(final ConstructorPassesThisOut obj, diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii index e373ae6f10..67ae620bac 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii @@ -1678,6 +1678,40 @@ } ] }, + "jsii-calc.ChildStruct982": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "experimental" + }, + "fqn": "jsii-calc.ChildStruct982", + "interfaces": [ + "jsii-calc.ParentStruct982" + ], + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2244 + }, + "name": "ChildStruct982", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "experimental" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2245 + }, + "name": "bar", + "type": { + "primitive": "number" + } + } + ] + }, "jsii-calc.ClassThatImplementsTheInternalInterface": { "assembly": "jsii-calc", "docs": { @@ -2825,6 +2859,62 @@ } ] }, + "jsii-calc.Demonstrate982": { + "assembly": "jsii-calc", + "docs": { + "remarks": "call #takeThis() -> An ObjectRef will be provisioned for the value (it'll be re-used!)\n2. call #takeThisToo() -> The ObjectRef from before will need to be down-cased to the ParentStruct982 type", + "stability": "experimental", + "summary": "1." + }, + "fqn": "jsii-calc.Demonstrate982", + "initializer": { + "docs": { + "stability": "experimental" + } + }, + "kind": "class", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2251 + }, + "methods": [ + { + "docs": { + "stability": "experimental", + "summary": "It's dangerous to go alone!" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2258 + }, + "name": "takeThis", + "returns": { + "type": { + "fqn": "jsii-calc.ChildStruct982" + } + }, + "static": true + }, + { + "docs": { + "stability": "experimental", + "summary": "It's dangerous to go alone!" + }, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2263 + }, + "name": "takeThisToo", + "returns": { + "type": { + "fqn": "jsii-calc.ParentStruct982" + } + }, + "static": true + } + ], + "name": "Demonstrate982" + }, "jsii-calc.DeprecatedClass": { "assembly": "jsii-calc", "docs": { @@ -7649,6 +7739,38 @@ ], "name": "OverrideReturnsObject" }, + "jsii-calc.ParentStruct982": { + "assembly": "jsii-calc", + "datatype": true, + "docs": { + "stability": "experimental", + "summary": "https://github.com/aws/jsii/issues/982." + }, + "fqn": "jsii-calc.ParentStruct982", + "kind": "interface", + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2241 + }, + "name": "ParentStruct982", + "properties": [ + { + "abstract": true, + "docs": { + "stability": "experimental" + }, + "immutable": true, + "locationInModule": { + "filename": "lib/compliance.ts", + "line": 2242 + }, + "name": "foo", + "type": { + "primitive": "string" + } + } + ] + }, "jsii-calc.PartiallyInitializedThisConsumer": { "abstract": true, "assembly": "jsii-calc", @@ -11006,5 +11128,5 @@ } }, "version": "0.20.3", - "fingerprint": "umMeNAH41pX11GUAjHkw6RTyAwGCeTqRNJ2vPv5aeM0=" + "fingerprint": "cb2xJuwu7eu9+ulwYnbZUyzYyE3IkL5fCM4b8Gqr7Vo=" } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ChildStruct982.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ChildStruct982.cs new file mode 100644 index 0000000000..b272f8f7d1 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ChildStruct982.cs @@ -0,0 +1,31 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// + /// stability: Experimental + /// + [JsiiByValue(fqn: "jsii-calc.ChildStruct982")] + public class ChildStruct982 : Amazon.JSII.Tests.CalculatorNamespace.IChildStruct982 + { + /// + /// stability: Experimental + /// + [JsiiProperty(name: "bar", typeJson: "{\"primitive\":\"number\"}", isOverride: true)] + public double Bar + { + get; + set; + } + + /// + /// stability: Experimental + /// + [JsiiProperty(name: "foo", typeJson: "{\"primitive\":\"string\"}", isOverride: true)] + public string Foo + { + get; + set; + } + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ChildStruct982Proxy.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ChildStruct982Proxy.cs new file mode 100644 index 0000000000..be2e6722df --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ChildStruct982Proxy.cs @@ -0,0 +1,33 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// + /// stability: Experimental + /// + [JsiiTypeProxy(nativeType: typeof(IChildStruct982), fullyQualifiedName: "jsii-calc.ChildStruct982")] + internal sealed class ChildStruct982Proxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IChildStruct982 + { + private ChildStruct982Proxy(ByRefValue reference): base(reference) + { + } + + /// + /// stability: Experimental + /// + [JsiiProperty(name: "bar", typeJson: "{\"primitive\":\"number\"}")] + public double Bar + { + get => GetInstanceProperty(); + } + + /// + /// stability: Experimental + /// + [JsiiProperty(name: "foo", typeJson: "{\"primitive\":\"string\"}")] + public string Foo + { + get => GetInstanceProperty(); + } + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Demonstrate982.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Demonstrate982.cs new file mode 100644 index 0000000000..d5a89526f1 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Demonstrate982.cs @@ -0,0 +1,49 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// 1. + /// + /// call #takeThis() -> An ObjectRef will be provisioned for the value (it'll be re-used!) + /// 2. call #takeThisToo() -> The ObjectRef from before will need to be down-cased to the ParentStruct982 type + /// stability: Experimental + /// + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Demonstrate982), fullyQualifiedName: "jsii-calc.Demonstrate982")] + public class Demonstrate982 : DeputyBase + { + /// + /// stability: Experimental + /// + public Demonstrate982(): base(new DeputyProps(new object[]{})) + { + } + + protected Demonstrate982(ByRefValue reference): base(reference) + { + } + + protected Demonstrate982(DeputyProps props): base(props) + { + } + + /// It's dangerous to go alone! + /// + /// stability: Experimental + /// + [JsiiMethod(name: "takeThis", returnsJson: "{\"type\":{\"fqn\":\"jsii-calc.ChildStruct982\"}}")] + public static Amazon.JSII.Tests.CalculatorNamespace.IChildStruct982 TakeThis() + { + return InvokeStaticMethod(typeof(Amazon.JSII.Tests.CalculatorNamespace.Demonstrate982), new System.Type[]{}, new object[]{}); + } + + /// It's dangerous to go alone! + /// + /// stability: Experimental + /// + [JsiiMethod(name: "takeThisToo", returnsJson: "{\"type\":{\"fqn\":\"jsii-calc.ParentStruct982\"}}")] + public static Amazon.JSII.Tests.CalculatorNamespace.IParentStruct982 TakeThisToo() + { + return InvokeStaticMethod(typeof(Amazon.JSII.Tests.CalculatorNamespace.Demonstrate982), new System.Type[]{}, new object[]{}); + } + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IChildStruct982.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IChildStruct982.cs new file mode 100644 index 0000000000..24a0643a53 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IChildStruct982.cs @@ -0,0 +1,20 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// + /// stability: Experimental + /// + [JsiiInterface(nativeType: typeof(IChildStruct982), fullyQualifiedName: "jsii-calc.ChildStruct982")] + public interface IChildStruct982 : Amazon.JSII.Tests.CalculatorNamespace.IParentStruct982 + { + /// + /// stability: Experimental + /// + [JsiiProperty(name: "bar", typeJson: "{\"primitive\":\"number\"}")] + double Bar + { + get; + } + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IParentStruct982.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IParentStruct982.cs new file mode 100644 index 0000000000..bee1e79e12 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IParentStruct982.cs @@ -0,0 +1,21 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// https://github.com/aws/jsii/issues/982. + /// + /// stability: Experimental + /// + [JsiiInterface(nativeType: typeof(IParentStruct982), fullyQualifiedName: "jsii-calc.ParentStruct982")] + public interface IParentStruct982 + { + /// + /// stability: Experimental + /// + [JsiiProperty(name: "foo", typeJson: "{\"primitive\":\"string\"}")] + string Foo + { + get; + } + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ParentStruct982.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ParentStruct982.cs new file mode 100644 index 0000000000..f57b3abe88 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ParentStruct982.cs @@ -0,0 +1,22 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// https://github.com/aws/jsii/issues/982. + /// + /// stability: Experimental + /// + [JsiiByValue(fqn: "jsii-calc.ParentStruct982")] + public class ParentStruct982 : Amazon.JSII.Tests.CalculatorNamespace.IParentStruct982 + { + /// + /// stability: Experimental + /// + [JsiiProperty(name: "foo", typeJson: "{\"primitive\":\"string\"}", isOverride: true)] + public string Foo + { + get; + set; + } + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ParentStruct982Proxy.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ParentStruct982Proxy.cs new file mode 100644 index 0000000000..d2dd223533 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ParentStruct982Proxy.cs @@ -0,0 +1,25 @@ +using Amazon.JSII.Runtime.Deputy; + +namespace Amazon.JSII.Tests.CalculatorNamespace +{ + /// https://github.com/aws/jsii/issues/982. + /// + /// stability: Experimental + /// + [JsiiTypeProxy(nativeType: typeof(IParentStruct982), fullyQualifiedName: "jsii-calc.ParentStruct982")] + internal sealed class ParentStruct982Proxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IParentStruct982 + { + private ParentStruct982Proxy(ByRefValue reference): base(reference) + { + } + + /// + /// stability: Experimental + /// + [JsiiProperty(name: "foo", typeJson: "{\"primitive\":\"string\"}")] + public string Foo + { + get => GetInstanceProperty(); + } + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java index 6479594f2d..1299a17b32 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/$Module.java @@ -33,6 +33,7 @@ protected Class resolveClass(final String fqn) throws ClassNotFoundException case "jsii-calc.BinaryOperation": return software.amazon.jsii.tests.calculator.BinaryOperation.class; case "jsii-calc.Calculator": return software.amazon.jsii.tests.calculator.Calculator.class; case "jsii-calc.CalculatorProps": return software.amazon.jsii.tests.calculator.CalculatorProps.class; + case "jsii-calc.ChildStruct982": return software.amazon.jsii.tests.calculator.ChildStruct982.class; case "jsii-calc.ClassThatImplementsTheInternalInterface": return software.amazon.jsii.tests.calculator.ClassThatImplementsTheInternalInterface.class; case "jsii-calc.ClassThatImplementsThePrivateInterface": return software.amazon.jsii.tests.calculator.ClassThatImplementsThePrivateInterface.class; case "jsii-calc.ClassWithCollections": return software.amazon.jsii.tests.calculator.ClassWithCollections.class; @@ -46,6 +47,7 @@ protected Class resolveClass(final String fqn) throws ClassNotFoundException case "jsii-calc.ConsumersOfThisCrazyTypeSystem": return software.amazon.jsii.tests.calculator.ConsumersOfThisCrazyTypeSystem.class; case "jsii-calc.DataRenderer": return software.amazon.jsii.tests.calculator.DataRenderer.class; case "jsii-calc.DefaultedConstructorArgument": return software.amazon.jsii.tests.calculator.DefaultedConstructorArgument.class; + case "jsii-calc.Demonstrate982": return software.amazon.jsii.tests.calculator.Demonstrate982.class; case "jsii-calc.DeprecatedClass": return software.amazon.jsii.tests.calculator.DeprecatedClass.class; case "jsii-calc.DeprecatedEnum": return software.amazon.jsii.tests.calculator.DeprecatedEnum.class; case "jsii-calc.DeprecatedStruct": return software.amazon.jsii.tests.calculator.DeprecatedStruct.class; @@ -140,6 +142,7 @@ protected Class resolveClass(final String fqn) throws ClassNotFoundException case "jsii-calc.OptionalStructConsumer": return software.amazon.jsii.tests.calculator.OptionalStructConsumer.class; case "jsii-calc.OverridableProtectedMember": return software.amazon.jsii.tests.calculator.OverridableProtectedMember.class; case "jsii-calc.OverrideReturnsObject": return software.amazon.jsii.tests.calculator.OverrideReturnsObject.class; + case "jsii-calc.ParentStruct982": return software.amazon.jsii.tests.calculator.ParentStruct982.class; case "jsii-calc.PartiallyInitializedThisConsumer": return software.amazon.jsii.tests.calculator.PartiallyInitializedThisConsumer.class; case "jsii-calc.Polymorphism": return software.amazon.jsii.tests.calculator.Polymorphism.class; case "jsii-calc.Power": return software.amazon.jsii.tests.calculator.Power.class; diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ChildStruct982.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ChildStruct982.java new file mode 100644 index 0000000000..9faeb87008 --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ChildStruct982.java @@ -0,0 +1,139 @@ +package software.amazon.jsii.tests.calculator; + +/** + * EXPERIMENTAL + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.ChildStruct982") +@software.amazon.jsii.Jsii.Proxy(ChildStruct982.Jsii$Proxy.class) +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) +public interface ChildStruct982 extends software.amazon.jsii.JsiiSerializable, software.amazon.jsii.tests.calculator.ParentStruct982 { + + /** + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + java.lang.Number getBar(); + + /** + * @return a {@link Builder} of {@link ChildStruct982} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link ChildStruct982} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public static final class Builder { + private java.lang.Number bar; + private java.lang.String foo; + + /** + * Sets the value of Bar + * @param bar the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public Builder bar(java.lang.Number bar) { + this.bar = bar; + return this; + } + + /** + * Sets the value of Foo + * @param foo the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public Builder foo(java.lang.String foo) { + this.foo = foo; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link ChildStruct982} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public ChildStruct982 build() { + return new Jsii$Proxy(bar, foo); + } + } + + /** + * An implementation for {@link ChildStruct982} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements ChildStruct982 { + private final java.lang.Number bar; + private final java.lang.String foo; + + /** + * Constructor that initializes the object based on values retrieved from the JsiiObject. + * @param objRef Reference to the JSII managed object. + */ + protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + this.bar = this.jsiiGet("bar", java.lang.Number.class); + this.foo = this.jsiiGet("foo", java.lang.String.class); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + private Jsii$Proxy(final java.lang.Number bar, final java.lang.String foo) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.bar = java.util.Objects.requireNonNull(bar, "bar is required"); + this.foo = java.util.Objects.requireNonNull(foo, "foo is required"); + } + + @Override + public java.lang.Number getBar() { + return this.bar; + } + + @Override + public java.lang.String getFoo() { + return this.foo; + } + + @Override + public com.fasterxml.jackson.databind.JsonNode $jsii$toJson() { + final com.fasterxml.jackson.databind.ObjectMapper om = software.amazon.jsii.JsiiObjectMapper.INSTANCE; + final com.fasterxml.jackson.databind.node.ObjectNode data = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + + data.set("bar", om.valueToTree(this.getBar())); + data.set("foo", om.valueToTree(this.getFoo())); + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.ChildStruct982")); + struct.set("data", data); + + final com.fasterxml.jackson.databind.node.ObjectNode obj = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + obj.set("$jsii.struct", struct); + + return obj; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ChildStruct982.Jsii$Proxy that = (ChildStruct982.Jsii$Proxy) o; + + if (!bar.equals(that.bar)) return false; + return this.foo.equals(that.foo); + } + + @Override + public int hashCode() { + int result = this.bar.hashCode(); + result = 31 * result + (this.foo.hashCode()); + return result; + } + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/Demonstrate982.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/Demonstrate982.java new file mode 100644 index 0000000000..8c2178c0ac --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/Demonstrate982.java @@ -0,0 +1,52 @@ +package software.amazon.jsii.tests.calculator; + +/** + * 1. + * + * call #takeThis() -> An ObjectRef will be provisioned for the value (it'll be re-used!) + * 2. call #takeThisToo() -> The ObjectRef from before will need to be down-cased to the ParentStruct982 type + * + * EXPERIMENTAL + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.Demonstrate982") +public class Demonstrate982 extends software.amazon.jsii.JsiiObject { + + protected Demonstrate982(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected Demonstrate982(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public Demonstrate982() { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + * It's dangerous to go alone! + * + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public static software.amazon.jsii.tests.calculator.ChildStruct982 takeThis() { + return software.amazon.jsii.JsiiObject.jsiiStaticCall(software.amazon.jsii.tests.calculator.Demonstrate982.class, "takeThis", software.amazon.jsii.tests.calculator.ChildStruct982.class); + } + + /** + * It's dangerous to go alone! + * + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public static software.amazon.jsii.tests.calculator.ParentStruct982 takeThisToo() { + return software.amazon.jsii.JsiiObject.jsiiStaticCall(software.amazon.jsii.tests.calculator.Demonstrate982.class, "takeThisToo", software.amazon.jsii.tests.calculator.ParentStruct982.class); + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ParentStruct982.java b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ParentStruct982.java new file mode 100644 index 0000000000..cec569befa --- /dev/null +++ b/packages/jsii-pacmak/test/expected.jsii-calc/java/src/main/java/software/amazon/jsii/tests/calculator/ParentStruct982.java @@ -0,0 +1,118 @@ +package software.amazon.jsii.tests.calculator; + +/** + * https://github.com/aws/jsii/issues/982. + * + * EXPERIMENTAL + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.ParentStruct982") +@software.amazon.jsii.Jsii.Proxy(ParentStruct982.Jsii$Proxy.class) +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) +public interface ParentStruct982 extends software.amazon.jsii.JsiiSerializable { + + /** + * EXPERIMENTAL + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + java.lang.String getFoo(); + + /** + * @return a {@link Builder} of {@link ParentStruct982} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + static Builder builder() { + return new Builder(); + } + /** + * A builder for {@link ParentStruct982} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public static final class Builder { + private java.lang.String foo; + + /** + * Sets the value of Foo + * @param foo the value to be set. This parameter is required. + * @return {@code this} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public Builder foo(java.lang.String foo) { + this.foo = foo; + return this; + } + + /** + * Builds the configured instance. + * @return a new instance of {@link ParentStruct982} + * @throws NullPointerException if any required attribute was not provided + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + public ParentStruct982 build() { + return new Jsii$Proxy(foo); + } + } + + /** + * An implementation for {@link ParentStruct982} + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental) + final class Jsii$Proxy extends software.amazon.jsii.JsiiObject implements ParentStruct982 { + private final java.lang.String foo; + + /** + * Constructor that initializes the object based on values retrieved from the JsiiObject. + * @param objRef Reference to the JSII managed object. + */ + protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + this.foo = this.jsiiGet("foo", java.lang.String.class); + } + + /** + * Constructor that initializes the object based on literal property values passed by the {@link Builder}. + */ + private Jsii$Proxy(final java.lang.String foo) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + this.foo = java.util.Objects.requireNonNull(foo, "foo is required"); + } + + @Override + public java.lang.String getFoo() { + return this.foo; + } + + @Override + public com.fasterxml.jackson.databind.JsonNode $jsii$toJson() { + final com.fasterxml.jackson.databind.ObjectMapper om = software.amazon.jsii.JsiiObjectMapper.INSTANCE; + final com.fasterxml.jackson.databind.node.ObjectNode data = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + + data.set("foo", om.valueToTree(this.getFoo())); + + final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + struct.set("fqn", om.valueToTree("jsii-calc.ParentStruct982")); + struct.set("data", data); + + final com.fasterxml.jackson.databind.node.ObjectNode obj = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode(); + obj.set("$jsii.struct", struct); + + return obj; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ParentStruct982.Jsii$Proxy that = (ParentStruct982.Jsii$Proxy) o; + + return this.foo.equals(that.foo); + } + + @Override + public int hashCode() { + int result = this.foo.hashCode(); + return result; + } + } +} diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py b/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py index 46ff4b2c6c..605a003b14 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py +++ b/packages/jsii-pacmak/test/expected.jsii-calc/python/src/jsii_calc/__init__.py @@ -1187,6 +1187,43 @@ def arg2(self) -> typing.Optional[str]: return jsii.get(self, "arg2") +class Demonstrate982(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.Demonstrate982"): + """1. + + call #takeThis() -> An ObjectRef will be provisioned for the value (it'll be re-used!) + 2. call #takeThisToo() -> The ObjectRef from before will need to be down-cased to the ParentStruct982 type + + stability + :stability: experimental + """ + def __init__(self) -> None: + """ + stability + :stability: experimental + """ + jsii.create(Demonstrate982, self, []) + + @jsii.member(jsii_name="takeThis") + @classmethod + def take_this(cls) -> "ChildStruct982": + """It's dangerous to go alone! + + stability + :stability: experimental + """ + return jsii.sinvoke(cls, "takeThis", []) + + @jsii.member(jsii_name="takeThisToo") + @classmethod + def take_this_too(cls) -> "ParentStruct982": + """It's dangerous to go alone! + + stability + :stability: experimental + """ + return jsii.sinvoke(cls, "takeThisToo", []) + + class DeprecatedClass(metaclass=jsii.JSIIMeta, jsii_type="jsii-calc.DeprecatedClass"): """ deprecated @@ -5432,6 +5469,79 @@ def test(self, obj: "IReturnsNumber") -> jsii.Number: return jsii.invoke(self, "test", [obj]) +@jsii.data_type(jsii_type="jsii-calc.ParentStruct982", jsii_struct_bases=[], name_mapping={'foo': 'foo'}) +class ParentStruct982(): + def __init__(self, *, foo: str): + """https://github.com/aws/jsii/issues/982. + + :param foo: + + stability + :stability: experimental + """ + self._values = { + 'foo': foo, + } + + @property + def foo(self) -> str: + """ + stability + :stability: experimental + """ + return self._values.get('foo') + + def __eq__(self, rhs) -> bool: + return isinstance(rhs, self.__class__) and rhs._values == self._values + + def __ne__(self, rhs) -> bool: + return not (rhs == self) + + def __repr__(self) -> str: + return 'ParentStruct982(%s)' % ', '.join(k + '=' + repr(v) for k, v in self._values.items()) + + +@jsii.data_type(jsii_type="jsii-calc.ChildStruct982", jsii_struct_bases=[ParentStruct982], name_mapping={'foo': 'foo', 'bar': 'bar'}) +class ChildStruct982(ParentStruct982): + def __init__(self, *, foo: str, bar: jsii.Number): + """ + :param foo: + :param bar: + + stability + :stability: experimental + """ + self._values = { + 'foo': foo, + 'bar': bar, + } + + @property + def foo(self) -> str: + """ + stability + :stability: experimental + """ + return self._values.get('foo') + + @property + def bar(self) -> jsii.Number: + """ + stability + :stability: experimental + """ + return self._values.get('bar') + + def __eq__(self, rhs) -> bool: + return isinstance(rhs, self.__class__) and rhs._values == self._values + + def __ne__(self, rhs) -> bool: + return not (rhs == self) + + def __repr__(self) -> str: + return 'ChildStruct982(%s)' % ', '.join(k + '=' + repr(v) for k, v in self._values.items()) + + class PartiallyInitializedThisConsumer(metaclass=jsii.JSIIAbstractClass, jsii_type="jsii-calc.PartiallyInitializedThisConsumer"): """ stability @@ -7733,6 +7843,6 @@ def parts(self, value: typing.List[scope.jsii_calc_lib.Value]): return jsii.set(self, "parts", value) -__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AnonymousImplementationProvider", "AsyncVirtualMethods", "AugmentableClass", "BaseJsii976", "Bell", "BinaryOperation", "Calculator", "CalculatorProps", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithCollections", "ClassWithDocs", "ClassWithJavaReservedWords", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumerCanRingBell", "ConsumersOfThisCrazyTypeSystem", "DataRenderer", "DefaultedConstructorArgument", "DeprecatedClass", "DeprecatedEnum", "DeprecatedStruct", "DerivedClassHasNoProperties", "DerivedStruct", "DiamondInheritanceBaseLevelStruct", "DiamondInheritanceFirstMidLevelStruct", "DiamondInheritanceSecondMidLevelStruct", "DiamondInheritanceTopLevelStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EnumDispenser", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExperimentalClass", "ExperimentalEnum", "ExperimentalStruct", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnonymousImplementationProvider", "IAnonymouslyImplementMe", "IAnotherPublicInterface", "IBell", "IBellRinger", "IConcreteBellRinger", "IDeprecatedInterface", "IExperimentalInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IJsii496", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnJsii976", "IReturnsNumber", "IStableInterface", "ImplementInternalInterface", "Implementation", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "InterfacesMaker", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "Jsii496Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NestedStruct", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalArgumentInvoker", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverridableProtectedMember", "OverrideReturnsObject", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RootStruct", "RootStructValidator", "RuntimeTypeChecking", "SecondLevelStruct", "SingleInstanceTwoTypes", "SingletonInt", "SingletonIntEnum", "SingletonString", "SingletonStringEnum", "SomeTypeJsii976", "StableClass", "StableEnum", "StableStruct", "StaticContext", "Statics", "StringEnum", "StripInternal", "StructA", "StructB", "StructPassing", "StructUnionConsumer", "StructWithJavaReservedWords", "Sum", "SupportsNiceJavaBuilder", "SupportsNiceJavaBuilderProps", "SupportsNiceJavaBuilderWithRequiredProps", "SyncVirtualMethods", "Thrower", "TopLevelStruct", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicInvoker", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "WithPrivatePropertyInConstructor", "__jsii_assembly__", "composition"] +__all__ = ["AbstractClass", "AbstractClassBase", "AbstractClassReturner", "Add", "AllTypes", "AllTypesEnum", "AllowedMethodNames", "AnonymousImplementationProvider", "AsyncVirtualMethods", "AugmentableClass", "BaseJsii976", "Bell", "BinaryOperation", "Calculator", "CalculatorProps", "ChildStruct982", "ClassThatImplementsTheInternalInterface", "ClassThatImplementsThePrivateInterface", "ClassWithCollections", "ClassWithDocs", "ClassWithJavaReservedWords", "ClassWithMutableObjectLiteralProperty", "ClassWithPrivateConstructorAndAutomaticProperties", "ConstructorPassesThisOut", "Constructors", "ConsumerCanRingBell", "ConsumersOfThisCrazyTypeSystem", "DataRenderer", "DefaultedConstructorArgument", "Demonstrate982", "DeprecatedClass", "DeprecatedEnum", "DeprecatedStruct", "DerivedClassHasNoProperties", "DerivedStruct", "DiamondInheritanceBaseLevelStruct", "DiamondInheritanceFirstMidLevelStruct", "DiamondInheritanceSecondMidLevelStruct", "DiamondInheritanceTopLevelStruct", "DoNotOverridePrivates", "DoNotRecognizeAnyAsOptional", "DocumentedClass", "DontComplainAboutVariadicAfterOptional", "DoubleTrouble", "EnumDispenser", "EraseUndefinedHashValues", "EraseUndefinedHashValuesOptions", "ExperimentalClass", "ExperimentalEnum", "ExperimentalStruct", "ExportedBaseClass", "ExtendsInternalInterface", "GiveMeStructs", "Greetee", "GreetingAugmenter", "IAnonymousImplementationProvider", "IAnonymouslyImplementMe", "IAnotherPublicInterface", "IBell", "IBellRinger", "IConcreteBellRinger", "IDeprecatedInterface", "IExperimentalInterface", "IExtendsPrivateInterface", "IFriendlier", "IFriendlyRandomGenerator", "IInterfaceImplementedByAbstractClass", "IInterfaceThatShouldNotBeADataType", "IInterfaceWithInternal", "IInterfaceWithMethods", "IInterfaceWithOptionalMethodArguments", "IInterfaceWithProperties", "IInterfaceWithPropertiesExtension", "IJSII417Derived", "IJSII417PublicBaseOfBase", "IJsii487External", "IJsii487External2", "IJsii496", "IMutableObjectLiteral", "INonInternalInterface", "IPrivatelyImplemented", "IPublicInterface", "IPublicInterface2", "IRandomNumberGenerator", "IReturnJsii976", "IReturnsNumber", "IStableInterface", "ImplementInternalInterface", "Implementation", "ImplementsInterfaceWithInternal", "ImplementsInterfaceWithInternalSubclass", "ImplementsPrivateInterface", "ImplictBaseOfBase", "InbetweenClass", "InterfaceInNamespaceIncludesClasses", "InterfaceInNamespaceOnlyInterface", "InterfacesMaker", "JSII417Derived", "JSII417PublicBaseOfBase", "JSObjectLiteralForInterface", "JSObjectLiteralToNative", "JSObjectLiteralToNativeClass", "JavaReservedWords", "Jsii487Derived", "Jsii496Derived", "JsiiAgent", "LoadBalancedFargateServiceProps", "Multiply", "Negate", "NestedStruct", "NodeStandardLibrary", "NullShouldBeTreatedAsUndefined", "NullShouldBeTreatedAsUndefinedData", "NumberGenerator", "ObjectRefsInCollections", "Old", "OptionalArgumentInvoker", "OptionalConstructorArgument", "OptionalStruct", "OptionalStructConsumer", "OverridableProtectedMember", "OverrideReturnsObject", "ParentStruct982", "PartiallyInitializedThisConsumer", "Polymorphism", "Power", "PublicClass", "PythonReservedWords", "ReferenceEnumFromScopedPackage", "ReturnsPrivateImplementationOfInterface", "RootStruct", "RootStructValidator", "RuntimeTypeChecking", "SecondLevelStruct", "SingleInstanceTwoTypes", "SingletonInt", "SingletonIntEnum", "SingletonString", "SingletonStringEnum", "SomeTypeJsii976", "StableClass", "StableEnum", "StableStruct", "StaticContext", "Statics", "StringEnum", "StripInternal", "StructA", "StructB", "StructPassing", "StructUnionConsumer", "StructWithJavaReservedWords", "Sum", "SupportsNiceJavaBuilder", "SupportsNiceJavaBuilderProps", "SupportsNiceJavaBuilderWithRequiredProps", "SyncVirtualMethods", "Thrower", "TopLevelStruct", "UnaryOperation", "UnionProperties", "UseBundledDependency", "UseCalcBase", "UsesInterfaceWithProperties", "VariadicInvoker", "VariadicMethod", "VirtualMethodPlayground", "VoidCallback", "WithPrivatePropertyInConstructor", "__jsii_assembly__", "composition"] publication.publish() diff --git a/packages/jsii-python-runtime/tests/test_compliance.py b/packages/jsii-python-runtime/tests/test_compliance.py index 93fcd3b166..179a5f405a 100644 --- a/packages/jsii-python-runtime/tests/test_compliance.py +++ b/packages/jsii-python-runtime/tests/test_compliance.py @@ -17,6 +17,7 @@ ConsumerCanRingBell, ConstructorPassesThisOut, DataRenderer, + Demonstrate982, DoNotOverridePrivates, DoubleTrouble, GreetingAugmenter, @@ -1039,6 +1040,10 @@ def test_return_subclass_that_implements_interface_976_raises_attributeerror_whe def test_return_anonymous_implementation_of_interface(): assert SomeTypeJsii976.return_anonymous() is not None +def test_structs_can_be_downcasted_to_parent_type(): + assert Demonstrate982.take_this() is not None + assert Demonstrate982.take_this_too() is not None + @jsii.implements(IBellRinger) class PythonBellRinger: def your_turn(self, bell): diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap index a3fe368aa3..15509c94d5 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.js.snap @@ -456,6 +456,15 @@ exports[`jsii-tree --all 1`] = ` │ │ └─┬ arg2 property (experimental) │ │ ├── immutable │ │ └── type: Optional + │ ├─┬ class Demonstrate982 (experimental) + │ │ └─┬ members + │ │ ├── () initializer (experimental) + │ │ ├─┬ static takeThis() method (experimental) + │ │ │ ├── static + │ │ │ └── returns: jsii-calc.ChildStruct982 + │ │ └─┬ static takeThisToo() method (experimental) + │ │ ├── static + │ │ └── returns: jsii-calc.ParentStruct982 │ ├─┬ class DeprecatedClass (deprecated) │ │ └─┬ members │ │ ├─┬ (readonlyString,mutableNumber) initializer (deprecated) @@ -1548,6 +1557,14 @@ exports[`jsii-tree --all 1`] = ` │ │ ├── abstract │ │ ├── immutable │ │ └── type: Optional + │ ├─┬ interface ChildStruct982 (experimental) + │ │ ├─┬ interfaces + │ │ │ └── ParentStruct982 + │ │ └─┬ members + │ │ └─┬ bar property (experimental) + │ │ ├── abstract + │ │ ├── immutable + │ │ └── type: number │ ├─┬ interface DeprecatedStruct (deprecated) │ │ └─┬ members │ │ └─┬ readonlyProperty property (deprecated) @@ -1934,6 +1951,12 @@ exports[`jsii-tree --all 1`] = ` │ │ ├── abstract │ │ ├── immutable │ │ └── type: Optional + │ ├─┬ interface ParentStruct982 (experimental) + │ │ └─┬ members + │ │ └─┬ foo property (experimental) + │ │ ├── abstract + │ │ ├── immutable + │ │ └── type: string │ ├─┬ interface RootStruct (experimental) │ │ └─┬ members │ │ ├─┬ stringProp property (experimental) @@ -2234,6 +2257,7 @@ exports[`jsii-tree --inheritance 1`] = ` │ ├── class ConsumersOfThisCrazyTypeSystem │ ├── class DataRenderer │ ├── class DefaultedConstructorArgument + │ ├── class Demonstrate982 │ ├── class DeprecatedClass │ ├── class Base │ ├─┬ class Derived @@ -2330,6 +2354,9 @@ exports[`jsii-tree --inheritance 1`] = ` │ ├─┬ class CompositeOperation │ │ └── base: Operation │ ├── interface CalculatorProps + │ ├─┬ interface ChildStruct982 + │ │ └─┬ interfaces + │ │ └── ParentStruct982 │ ├── interface DeprecatedStruct │ ├─┬ interface DerivedStruct │ │ └─┬ interfaces @@ -2403,6 +2430,7 @@ exports[`jsii-tree --inheritance 1`] = ` │ ├── interface NestedStruct │ ├── interface NullShouldBeTreatedAsUndefinedData │ ├── interface OptionalStruct + │ ├── interface ParentStruct982 │ ├── interface RootStruct │ ├── interface SecondLevelStruct │ ├── interface StableStruct @@ -2639,6 +2667,11 @@ exports[`jsii-tree --members 1`] = ` │ │ ├── arg1 property │ │ ├── arg3 property │ │ └── arg2 property + │ ├─┬ class Demonstrate982 + │ │ └─┬ members + │ │ ├── () initializer + │ │ ├── static takeThis() method + │ │ └── static takeThisToo() method │ ├─┬ class DeprecatedClass │ │ └─┬ members │ │ ├── (readonlyString,mutableNumber) initializer @@ -3122,6 +3155,9 @@ exports[`jsii-tree --members 1`] = ` │ │ └─┬ members │ │ ├── initialValue property │ │ └── maximumValue property + │ ├─┬ interface ChildStruct982 + │ │ └─┬ members + │ │ └── bar property │ ├─┬ interface DeprecatedStruct │ │ └─┬ members │ │ └── readonlyProperty property @@ -3291,6 +3327,9 @@ exports[`jsii-tree --members 1`] = ` │ ├─┬ interface OptionalStruct │ │ └─┬ members │ │ └── field property + │ ├─┬ interface ParentStruct982 + │ │ └─┬ members + │ │ └── foo property │ ├─┬ interface RootStruct │ │ └─┬ members │ │ ├── stringProp property @@ -3459,6 +3498,7 @@ exports[`jsii-tree --types 1`] = ` │ ├── class ConsumersOfThisCrazyTypeSystem │ ├── class DataRenderer │ ├── class DefaultedConstructorArgument + │ ├── class Demonstrate982 │ ├── class DeprecatedClass │ ├── class Base │ ├── class Derived @@ -3537,6 +3577,7 @@ exports[`jsii-tree --types 1`] = ` │ ├── class WithPrivatePropertyInConstructor │ ├── class CompositeOperation │ ├── interface CalculatorProps + │ ├── interface ChildStruct982 │ ├── interface DeprecatedStruct │ ├── interface DerivedStruct │ ├── interface DiamondInheritanceBaseLevelStruct @@ -3586,6 +3627,7 @@ exports[`jsii-tree --types 1`] = ` │ ├── interface NestedStruct │ ├── interface NullShouldBeTreatedAsUndefinedData │ ├── interface OptionalStruct + │ ├── interface ParentStruct982 │ ├── interface RootStruct │ ├── interface SecondLevelStruct │ ├── interface StableStruct diff --git a/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap b/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap index 1305905b47..ef1341676d 100644 --- a/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap +++ b/packages/jsii-reflect/test/__snapshots__/type-system.test.js.snap @@ -40,6 +40,7 @@ Array [ "ConsumersOfThisCrazyTypeSystem", "DataRenderer", "DefaultedConstructorArgument", + "Demonstrate982", "DeprecatedClass", "Derived", "DoNotOverridePrivates",