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 f303b84aa2..2c6b9dff3c 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 @@ -1033,6 +1033,13 @@ public void VariadicCallbacksAreHandledCorrectly() Assert.Equal(new double[]{2d, 3d, 4d}, invoker.AsArray(1, 2, 3)); } + [Fact(DisplayName = Prefix + nameof(ReturnSubclassThatImplementsInterface976))] + public void ReturnSubclassThatImplementsInterface976() + { + var obj = SomeTypeJsii976.ReturnReturn(); + Assert.Equal(obj.Foo, 333); + } + private sealed class OverrideVariadicMethod : VariadicMethod { public override double[] AsArray(double first, params double[] others) 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 a904d729d5..45d8ca4ff8 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 @@ -1391,6 +1391,12 @@ public void correctlyDeserializesStructUnions() { assertTrue(StructUnionConsumer.isStructB(b1)); } + @Test + public void returnSubclassThatImplementsInterface976() { + IReturnJsii976 obj = SomeTypeJsii976.returnReturn(); + assertEquals(obj.getFoo(), 333); + } + static class PartiallyInitializedThisConsumerImpl extends PartiallyInitializedThisConsumer { @Override public String consumePartiallyInitializedThis(final ConstructorPassesThisOut obj, diff --git a/packages/jsii-python-runtime/tests/test_compliance.py b/packages/jsii-python-runtime/tests/test_compliance.py index 996e004e67..93fcd3b166 100644 --- a/packages/jsii-python-runtime/tests/test_compliance.py +++ b/packages/jsii-python-runtime/tests/test_compliance.py @@ -55,7 +55,9 @@ StructA, StructB, StructUnionConsumer, - SomeTypeJsii976 + SomeTypeJsii976, + AnonymousImplementationProvider, + IAnonymousImplementationProvider ) from scope.jsii_calc_lib import IFriendly, EnumFromScopedModule, Number @@ -1013,6 +1015,12 @@ def test_can_pass_nested_struct_as_dict(): } ) +def test_can_leverage_indirect_interface_polymorphism(): + provider = AnonymousImplementationProvider() + assert provider.provide_as_class().value == 1337 + assert provider.provide_as_interface().value == 1337 + assert provider.provide_as_interface().verb() == "to implement" + # https://github.com/aws/jsii/issues/976 def test_return_subclass_that_implements_interface_976(): obj = SomeTypeJsii976.return_return()