From da55a1e9add0f8c903ef6f4aa5085f2a3d5a360b Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Mon, 11 Oct 2021 15:18:40 +0200 Subject: [PATCH] fix(python): unknown type when submodule is not loaded (#3049) Callbacks may make references to types from submodules of loaded packages, however due to how the type registration works in the Python runtime, if the submodule has not been loaded, then the types it contains are not registered and will fail resolving. The simplest possible fix is to preemtively load all submodules upfront at the end of the root module's `__init__.py` file, which guarantees that all types have correctly been registered in the runtime (at the expense of some time and memory). Fixes aws/aws-cdk#16625 --- .../specification/6-compliance-report.md | 3 +- .../ComplianceTests.cs | 15 +- .../project/compliance_test.go | 6 + .../project/internal/cdk16625/cdk16625.go | 20 ++ .../amazon/jsii/testing/ComplianceTest.java | 12 ++ .../python-runtime/tests/test_compliance.py | 17 ++ .../lib/cdk16625/donotimport/index.ts | 22 ++ packages/jsii-calc/lib/cdk16625/index.ts | 26 +++ packages/jsii-calc/lib/index.ts | 2 + packages/jsii-calc/test/assembly.jsii | 135 +++++++++++- packages/jsii-pacmak/lib/targets/python.ts | 39 +++- .../__snapshots__/target-dotnet.test.ts.snap | 113 ++++++++++ .../__snapshots__/target-go.test.ts.snap | 195 ++++++++++++++++++ .../__snapshots__/target-java.test.ts.snap | 120 +++++++++++ .../__snapshots__/target-python.test.ts.snap | 155 ++++++++++++++ .../test/__snapshots__/jsii-tree.test.ts.snap | 61 ++++++ .../test/__snapshots__/tree.test.ts.snap | 45 ++++ .../__snapshots__/type-system.test.ts.snap | 2 + tools/jsii-compliance/suite.ts | 4 + 19 files changed, 988 insertions(+), 4 deletions(-) create mode 100644 packages/@jsii/go-runtime-test/project/internal/cdk16625/cdk16625.go create mode 100644 packages/jsii-calc/lib/cdk16625/donotimport/index.ts create mode 100644 packages/jsii-calc/lib/cdk16625/index.ts diff --git a/gh-pages/content/specification/6-compliance-report.md b/gh-pages/content/specification/6-compliance-report.md index 0317931d80..82aec9f08e 100644 --- a/gh-pages/content/specification/6-compliance-report.md +++ b/gh-pages/content/specification/6-compliance-report.md @@ -5,7 +5,7 @@ This section details the current state of each language binding with respect to our standard compliance suite. -| number | test | java (99.15%) | golang (77.97%) | Dotnet | Python | +| number | test | java (99.16%) | golang (78.15%) | Dotnet | Python | | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | -------------------------------------------- | ------ | ------ | | 1 | asyncOverrides_overrideCallsSuper | 🟢 | [🔴](https://github.com/aws/jsii/issues/2670) | ⭕ | ⭕ | | 2 | [arrayReturnedByMethodCanBeRead]("Array created in the kernel can be queried for its elements") | 🟢 | 🟢 | ⭕ | ⭕ | @@ -125,3 +125,4 @@ This section details the current state of each language binding with respect to | 116 | subclassing | 🟢 | 🟢 | ⭕ | ⭕ | | 117 | testInterfaces | 🟢 | 🟢 | ⭕ | ⭕ | | 118 | [callbackParameterIsInterface]("Validates pure interfaces can be passed to callbacks") | ⭕ | 🟢 | ⭕ | ⭕ | +| 119 | [classCanBeUsedWhenNotExpressedlyLoaded]("Validates that types not explicitly loaded by the user can safely be returned by JS code") | 🟢 | 🟢 | ⭕ | ⭕ | 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 0177bfe499..d3df89f7a1 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 @@ -3,6 +3,7 @@ using System.Linq; using Amazon.JSII.Runtime.Deputy; using Amazon.JSII.Tests.CalculatorNamespace; +using Amazon.JSII.Tests.CalculatorNamespace.Cdk16625; using CompositeOperation = Amazon.JSII.Tests.CalculatorNamespace.Composition.CompositeOperation; using Amazon.JSII.Tests.CalculatorNamespace.LibNamespace; using Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace; @@ -1522,8 +1523,20 @@ public void ArrayOfInterfaces() var allTypes = new AllTypes(); allTypes.AnyProperty = bells; - + Assert.Equal(bells, allTypes.AnyProperty); } + + [Fact(DisplayName = Prefix + nameof(ClassCanBeUsedWhenNotExpressedlyLoaded))] + public void ClassCanBeUsedWhenNotExpressedlyLoaded() + { + new Cdk16625Impl().Test(); + } + + private sealed class Cdk16625Impl: Cdk16625 { + protected override double Unwrap(IRandomNumberGenerator rng) { + return rng.Next(); + } + } } } diff --git a/packages/@jsii/go-runtime-test/project/compliance_test.go b/packages/@jsii/go-runtime-test/project/compliance_test.go index 4c65ac5afc..bc2f1c1247 100644 --- a/packages/@jsii/go-runtime-test/project/compliance_test.go +++ b/packages/@jsii/go-runtime-test/project/compliance_test.go @@ -11,6 +11,7 @@ import ( "github.com/aws/jsii-runtime-go" "github.com/aws/jsii/go-runtime-test/internal/addTen" "github.com/aws/jsii/go-runtime-test/internal/bellRinger" + "github.com/aws/jsii/go-runtime-test/internal/cdk16625" "github.com/aws/jsii/go-runtime-test/internal/doNotOverridePrivates" "github.com/aws/jsii/go-runtime-test/internal/friendlyRandom" "github.com/aws/jsii/go-runtime-test/internal/overrideAsyncMethods" @@ -1640,6 +1641,11 @@ func (suite *ComplianceSuite) TestCallbackParameterIsInterface() { require.True(*calc.ConsumerCanRingBell_StaticImplementedByPublicClass(ringer)) } +func (suite *ComplianceSuite) TestClassCanBeUsedWhenNotExpressedlyLoaded() { + cdk16625.New().Test() +} + + // required to make `go test` recognize the suite. func TestComplianceSuite(t *testing.T) { suite.Run(t, new(ComplianceSuite)) diff --git a/packages/@jsii/go-runtime-test/project/internal/cdk16625/cdk16625.go b/packages/@jsii/go-runtime-test/project/internal/cdk16625/cdk16625.go new file mode 100644 index 0000000000..aef3945a2a --- /dev/null +++ b/packages/@jsii/go-runtime-test/project/internal/cdk16625/cdk16625.go @@ -0,0 +1,20 @@ +package cdk16625 + +import ( + "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3" + abc "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/cdk16625" +) + +func New() abc.Cdk16625 { + c := &cdk16625{} + abc.NewCdk16625_Override(c) + return c +} + +type cdk16625 struct{ + abc.Cdk16625 +} + +func (c *cdk16625) Unwrap(rng jsiicalc.IRandomNumberGenerator) *float64 { + return rng.Next() +} 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 b45edb4eb8..673397e3ef 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 @@ -11,6 +11,7 @@ import software.amazon.jsii.ReloadingClassLoader; import software.amazon.jsii.tests.calculator.*; import software.amazon.jsii.tests.calculator.baseofbase.StaticConsumer; +import software.amazon.jsii.tests.calculator.cdk16625.Cdk16625; import software.amazon.jsii.tests.calculator.composition.CompositeOperation; import software.amazon.jsii.tests.calculator.custom_submodule_name.NestingClass.NestedStruct; import software.amazon.jsii.tests.calculator.lib.EnumFromScopedModule; @@ -1799,4 +1800,15 @@ public String repeat(final String word) { assertEquals(nowAsISO, entropy.increase()); } + + @Test + public void classCanBeUsedWhenNotExpressedlyLoaded() { + final Cdk16625 subject = new Cdk16625() { + @Override + protected java.lang.Number unwrap(final IRandomNumberGenerator rng) { + return rng.next(); + } + }; + subject.test(); + } } diff --git a/packages/@jsii/python-runtime/tests/test_compliance.py b/packages/@jsii/python-runtime/tests/test_compliance.py index b46214e1c4..28f2ddf590 100644 --- a/packages/@jsii/python-runtime/tests/test_compliance.py +++ b/packages/@jsii/python-runtime/tests/test_compliance.py @@ -76,6 +76,7 @@ AnonymousImplementationProvider, UpcasingReflectable, ) +from jsii_calc.cdk16625 import Cdk16625 from jsii_calc.python_self import ( ClassWithSelf, ClassWithSelfKwarg, @@ -1318,3 +1319,19 @@ def repeat(self, word: str) -> str: entropy = MildEntropy(wall_clock) assert now == entropy.increase() + + +def test_class_can_be_used_when_not_expressedly_loaded(): + """ + This test verifies that it is possible to receive instances of classes that + belong to submodules that have not been explicitly imported. This implies + the types are registered with the runtime even though the submodule has + never been mentioned in userland. + """ + + class Subject(Cdk16625): + def _unwrap(self, rng: IRandomNumberGenerator): + return rng.next() + + # This should NOT throw + Subject().test() diff --git a/packages/jsii-calc/lib/cdk16625/donotimport/index.ts b/packages/jsii-calc/lib/cdk16625/donotimport/index.ts new file mode 100644 index 0000000000..593bf207bc --- /dev/null +++ b/packages/jsii-calc/lib/cdk16625/donotimport/index.ts @@ -0,0 +1,22 @@ +import type { IRandomNumberGenerator } from '../../calculator'; + +/** + * This type demonstrates the ability to receive a callback argument that has a + * type from a submodule not explicitly imported in the user's code. This checks + * that all types available in the assembly can be resolved by the runtime + * library, regardless of whether they were explicitly referenced or not. + * + * @see https://github.com/aws/aws-cdk/issues/16625 + */ +export class UnimportedSubmoduleType implements IRandomNumberGenerator { + public constructor(private readonly value: number) {} + + /** + * Not quite random, but it'll do. + * + * @returns 1337 + */ + public next(): number { + return this.value; + } +} diff --git a/packages/jsii-calc/lib/cdk16625/index.ts b/packages/jsii-calc/lib/cdk16625/index.ts new file mode 100644 index 0000000000..ffe62c0911 --- /dev/null +++ b/packages/jsii-calc/lib/cdk16625/index.ts @@ -0,0 +1,26 @@ +import * as assert from 'assert'; + +import { IRandomNumberGenerator } from '../calculator'; +import { UnimportedSubmoduleType } from './donotimport'; + +export * as donotimport from './donotimport'; + +export abstract class Cdk16625 { + /** + * Implement this functin to return `gen.next()`. It is extremely important + * that the `donotimport` submodule is NEVER explicitly loaded in the testing + * application (otherwise this test is void). + * + * @param gen a VERY pseudo random number generator. + */ + protected abstract unwrap(gen: IRandomNumberGenerator): number; + + /** + * Run this function to verify that everything is working as it should. + */ + public test(): void { + const value = 1337; + const rng = new UnimportedSubmoduleType(value); + assert(this.unwrap(rng) === value); + } +} diff --git a/packages/jsii-calc/lib/index.ts b/packages/jsii-calc/lib/index.ts index e66664ba2f..397ce7a103 100644 --- a/packages/jsii-calc/lib/index.ts +++ b/packages/jsii-calc/lib/index.ts @@ -19,3 +19,5 @@ export * as module2702 from './module2702'; export * as module2692 from './module2692'; export * as module2530 from './module2530'; export * as module2700 from './module2700'; + +export * as cdk16625 from './cdk16625'; diff --git a/packages/jsii-calc/test/assembly.jsii b/packages/jsii-calc/test/assembly.jsii index 058d50bbc4..8b57e4e827 100644 --- a/packages/jsii-calc/test/assembly.jsii +++ b/packages/jsii-calc/test/assembly.jsii @@ -205,6 +205,18 @@ "line": 1090 } }, + "jsii-calc.cdk16625": { + "locationInModule": { + "filename": "lib/index.ts", + "line": 23 + } + }, + "jsii-calc.cdk16625.donotimport": { + "locationInModule": { + "filename": "lib/cdk16625/index.ts", + "line": 6 + } + }, "jsii-calc.composition": { "locationInModule": { "filename": "lib/calculator.ts", @@ -14607,6 +14619,127 @@ ], "symbolId": "lib/compliance:WithPrivatePropertyInConstructor" }, + "jsii-calc.cdk16625.Cdk16625": { + "abstract": true, + "assembly": "jsii-calc", + "docs": { + "stability": "stable" + }, + "fqn": "jsii-calc.cdk16625.Cdk16625", + "initializer": { + "docs": { + "stability": "stable" + } + }, + "kind": "class", + "locationInModule": { + "filename": "lib/cdk16625/index.ts", + "line": 8 + }, + "methods": [ + { + "docs": { + "stability": "stable", + "summary": "Run this function to verify that everything is working as it should." + }, + "locationInModule": { + "filename": "lib/cdk16625/index.ts", + "line": 21 + }, + "name": "test" + }, + { + "abstract": true, + "docs": { + "stability": "stable", + "summary": "Implement this functin to return `gen.next()`. It is extremely important that the `donotimport` submodule is NEVER explicitly loaded in the testing application (otherwise this test is void)." + }, + "locationInModule": { + "filename": "lib/cdk16625/index.ts", + "line": 16 + }, + "name": "unwrap", + "parameters": [ + { + "docs": { + "summary": "a VERY pseudo random number generator." + }, + "name": "gen", + "type": { + "fqn": "jsii-calc.IRandomNumberGenerator" + } + } + ], + "protected": true, + "returns": { + "type": { + "primitive": "number" + } + } + } + ], + "name": "Cdk16625", + "namespace": "cdk16625", + "symbolId": "lib/cdk16625/index:Cdk16625" + }, + "jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType": { + "assembly": "jsii-calc", + "docs": { + "remarks": "This checks\nthat all types available in the assembly can be resolved by the runtime\nlibrary, regardless of whether they were explicitly referenced or not.", + "see": "https://github.com/aws/aws-cdk/issues/16625", + "stability": "stable", + "summary": "This type demonstrates the ability to receive a callback argument that has a type from a submodule not explicitly imported in the user's code." + }, + "fqn": "jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType", + "initializer": { + "docs": { + "stability": "stable" + }, + "locationInModule": { + "filename": "lib/cdk16625/donotimport/index.ts", + "line": 12 + }, + "parameters": [ + { + "name": "value", + "type": { + "primitive": "number" + } + } + ] + }, + "interfaces": [ + "jsii-calc.IRandomNumberGenerator" + ], + "kind": "class", + "locationInModule": { + "filename": "lib/cdk16625/donotimport/index.ts", + "line": 11 + }, + "methods": [ + { + "docs": { + "returns": "1337", + "stability": "stable", + "summary": "Not quite random, but it'll do." + }, + "locationInModule": { + "filename": "lib/cdk16625/donotimport/index.ts", + "line": 19 + }, + "name": "next", + "overrides": "jsii-calc.IRandomNumberGenerator", + "returns": { + "type": { + "primitive": "number" + } + } + } + ], + "name": "UnimportedSubmoduleType", + "namespace": "cdk16625.donotimport", + "symbolId": "lib/cdk16625/donotimport/index:UnimportedSubmoduleType" + }, "jsii-calc.composition.CompositeOperation": { "abstract": true, "assembly": "jsii-calc", @@ -16646,5 +16779,5 @@ } }, "version": "3.20.120", - "fingerprint": "f6AcTsdiyd7A1OsnCqScIhOj+U5gmsZC6YnZSsCDh+M=" + "fingerprint": "2ST30e+9gb6XYfIMHyGjwObar3fI+/BV0Ex1hIad+2s=" } diff --git a/packages/jsii-pacmak/lib/targets/python.ts b/packages/jsii-pacmak/lib/targets/python.ts index 2e2eae1410..8c052b67f6 100644 --- a/packages/jsii-pacmak/lib/targets/python.ts +++ b/packages/jsii-pacmak/lib/targets/python.ts @@ -1,4 +1,5 @@ import * as spec from '@jsii/spec'; +import * as assert from 'assert'; import { CodeMaker, toSnakeCase } from 'codemaker'; import * as escapeStringRegexp from 'escape-string-regexp'; import * as fs from 'fs-extra'; @@ -1488,6 +1489,8 @@ class PythonModule implements PythonType { private readonly loadAssembly: boolean; private readonly members = new Array(); + private readonly modules = new Array(); + public constructor( public readonly pythonName: string, public readonly fqn: string | undefined, @@ -1503,6 +1506,14 @@ class PythonModule implements PythonType { this.members.push(member); } + public addPythonModule(pyMod: PythonModule) { + assert( + !this.loadAssembly, + 'PythonModule.addPythonModule CANNOT be called on assembly-loading modules (it would cause a load cycle)!', + ); + this.modules.push(pyMod); + } + public requiredImports(context: EmitContext): PythonImports { return mergePythonImports( ...this.members.map((mem) => mem.requiredImports(context)), @@ -1595,10 +1606,23 @@ class PythonModule implements PythonType { code.line('__all__: typing.List[typing.Any] = []'); } - // Finally, we'll use publication to ensure that all of the non-public names + // Next up, we'll use publication to ensure that all of the non-public names // get hidden from dir(), tab-complete, etc. code.line(); code.line('publication.publish()'); + + // Finally, we'll load all registered python modules + if (this.modules.length > 0) { + code.line(); + code.line( + '# Loading modules to ensure their types are registered with the jsii runtime library', + ); + for (const module of this.modules.sort((l, r) => + l.pythonName.localeCompare(r.pythonName), + )) { + code.line(`import ${module.pythonName}`); + } + } } /** @@ -2144,6 +2168,7 @@ class TypeResolver { class PythonGenerator extends Generator { private package!: Package; + private rootModule?: PythonModule; private readonly types: Map; public constructor( @@ -2408,6 +2433,18 @@ class PythonGenerator extends Generator { // This applies recursively to submodules, so no need to duplicate! this.package.addData(module, 'py.typed', ''); } + + if (ns === this.assembly.name) { + this.rootModule = module; + } else { + this.rootModule!.addPythonModule(module); + } + } + + protected onEndNamespace(ns: string) { + if (ns === this.assembly.name) { + delete this.rootModule; + } } protected onBeginClass(cls: spec.ClassType, abstract: boolean | undefined) { diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index fbb599d21d..7a39a3a9fc 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -2730,6 +2730,10 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 BurriedAnonymousObject.cs ┃ ┣━ 📄 Calculator.cs ┃ ┣━ 📄 CalculatorProps.cs + ┃ ┣━ 📁 Cdk16625 + ┃ ┃ ┣━ 📄 Cdk16625.cs + ┃ ┃ ┗━ 📁 Donotimport + ┃ ┃ ┗━ 📄 UnimportedSubmoduleType.cs ┃ ┣━ 📄 ChildStruct982.cs ┃ ┣━ 📄 ClassThatImplementsTheInternalInterface.cs ┃ ┣━ 📄 ClassThatImplementsThePrivateInterface.cs @@ -4291,6 +4295,115 @@ namespace Amazon.JSII.Tests.CalculatorNamespace `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Cdk16625/Cdk16625.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Cdk16625 +{ + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Cdk16625.Cdk16625), fullyQualifiedName: "jsii-calc.cdk16625.Cdk16625")] + public abstract class Cdk16625 : DeputyBase + { + protected Cdk16625(): base(new DeputyProps(System.Array.Empty())) + { + } + + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected Cdk16625(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected Cdk16625(DeputyProps props): base(props) + { + } + + /// Run this function to verify that everything is working as it should. + [JsiiMethod(name: "test")] + public virtual void Test() + { + InvokeInstanceVoidMethod(new System.Type[]{}, new object[]{}); + } + + /// Implement this functin to return \`gen.next()\`. It is extremely important that the \`donotimport\` submodule is NEVER explicitly loaded in the testing application (otherwise this test is void). + /// a VERY pseudo random number generator. + [JsiiMethod(name: "unwrap", returnsJson: "{\\"type\\":{\\"primitive\\":\\"number\\"}}", parametersJson: "[{\\"docs\\":{\\"summary\\":\\"a VERY pseudo random number generator.\\"},\\"name\\":\\"gen\\",\\"type\\":{\\"fqn\\":\\"jsii-calc.IRandomNumberGenerator\\"}}]")] + protected abstract double Unwrap(Amazon.JSII.Tests.CalculatorNamespace.IRandomNumberGenerator gen); + + + [JsiiTypeProxy(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Cdk16625.Cdk16625), fullyQualifiedName: "jsii-calc.cdk16625.Cdk16625")] + internal sealed class _Proxy : Amazon.JSII.Tests.CalculatorNamespace.Cdk16625.Cdk16625 + { + private _Proxy(ByRefValue reference): base(reference) + { + } + + /// Implement this functin to return \`gen.next()\`. It is extremely important that the \`donotimport\` submodule is NEVER explicitly loaded in the testing application (otherwise this test is void). + /// a VERY pseudo random number generator. + [JsiiMethod(name: "unwrap", returnsJson: "{\\"type\\":{\\"primitive\\":\\"number\\"}}", parametersJson: "[{\\"docs\\":{\\"summary\\":\\"a VERY pseudo random number generator.\\"},\\"name\\":\\"gen\\",\\"type\\":{\\"fqn\\":\\"jsii-calc.IRandomNumberGenerator\\"}}]")] + protected override double Unwrap(Amazon.JSII.Tests.CalculatorNamespace.IRandomNumberGenerator gen) + { + return InvokeInstanceMethod(new System.Type[]{typeof(Amazon.JSII.Tests.CalculatorNamespace.IRandomNumberGenerator)}, new object[]{gen})!; + } + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Cdk16625/Donotimport/UnimportedSubmoduleType.cs 1`] = ` +using Amazon.JSII.Runtime.Deputy; + +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.Cdk16625.Donotimport +{ + /// This type demonstrates the ability to receive a callback argument that has a type from a submodule not explicitly imported in the user's code. + /// + /// This checks + /// that all types available in the assembly can be resolved by the runtime + /// library, regardless of whether they were explicitly referenced or not. + /// + /// See: https://github.com/aws/aws-cdk/issues/16625 + /// + [JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.Cdk16625.Donotimport.UnimportedSubmoduleType), fullyQualifiedName: "jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType", parametersJson: "[{\\"name\\":\\"value\\",\\"type\\":{\\"primitive\\":\\"number\\"}}]")] + public class UnimportedSubmoduleType : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IRandomNumberGenerator + { + public UnimportedSubmoduleType(double @value): base(new DeputyProps(new object?[]{@value})) + { + } + + /// Used by jsii to construct an instance of this class from a Javascript-owned object reference + /// The Javascript-owned object reference + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected UnimportedSubmoduleType(ByRefValue reference): base(reference) + { + } + + /// Used by jsii to construct an instance of this class from DeputyProps + /// The deputy props + [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + protected UnimportedSubmoduleType(DeputyProps props): base(props) + { + } + + /// Not quite random, but it'll do. + /// 1337 + [JsiiMethod(name: "next", returnsJson: "{\\"type\\":{\\"primitive\\":\\"number\\"}}", isOverride: true)] + public virtual double Next() + { + return InvokeInstanceMethod(new System.Type[]{}, new object[]{})!; + } + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ChildStruct982.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap index 2f3e6ec3c0..86f1d64f4e 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-go.test.ts.snap @@ -1940,6 +1940,14 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┗━ 📁 go ┗━ 📁 jsiicalc + ┣━ 📁 cdk16625 + ┃ ┣━ 📄 cdk16625.go + ┃ ┣━ 📄 cdk16625.init.go + ┃ ┗━ 📁 donotimport + ┃ ┣━ 📄 donotimport.go + ┃ ┣━ 📄 donotimport.init.go + ┃ ┗━ 📁 internal + ┃ ┗━ 📄 types.go ┣━ 📁 composition ┃ ┣━ 📄 composition.go ┃ ┣━ 📄 composition.init.go @@ -2290,6 +2298,193 @@ const foo = 'bar'; \`\`\` +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/cdk16625/cdk16625.go 1`] = ` +package cdk16625 + +import ( + _jsii_ "github.com/aws/jsii-runtime-go/runtime" + _init_ "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/jsii" + + "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3" +) + +type Cdk16625 interface { + Test() + Unwrap(gen jsiicalc.IRandomNumberGenerator) *float64 +} + +// The jsii proxy struct for Cdk16625 +type jsiiProxy_Cdk16625 struct { + _ byte // padding +} + +func NewCdk16625_Override(c Cdk16625) { + _init_.Initialize() + + _jsii_.Create( + "jsii-calc.cdk16625.Cdk16625", + nil, // no parameters + c, + ) +} + +// Run this function to verify that everything is working as it should. +func (c *jsiiProxy_Cdk16625) Test() { + _jsii_.InvokeVoid( + c, + "test", + nil, // no parameters + ) +} + +// Implement this functin to return \`gen.next()\`. It is extremely important that the \`donotimport\` submodule is NEVER explicitly loaded in the testing application (otherwise this test is void). +func (c *jsiiProxy_Cdk16625) Unwrap(gen jsiicalc.IRandomNumberGenerator) *float64 { + var returns *float64 + + _jsii_.Invoke( + c, + "unwrap", + []interface{}{gen}, + &returns, + ) + + return returns +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/cdk16625/cdk16625.init.go 1`] = ` +package cdk16625 + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go/runtime" +) + +func init() { + _jsii_.RegisterClass( + "jsii-calc.cdk16625.Cdk16625", + reflect.TypeOf((*Cdk16625)(nil)).Elem(), + []_jsii_.Member{ + _jsii_.MemberMethod{JsiiMethod: "test", GoMethod: "Test"}, + _jsii_.MemberMethod{JsiiMethod: "unwrap", GoMethod: "Unwrap"}, + }, + func() interface{} { + return &jsiiProxy_Cdk16625{} + }, + ) +} + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/cdk16625/donotimport/donotimport.go 1`] = ` +package donotimport + +import ( + _jsii_ "github.com/aws/jsii-runtime-go/runtime" + _init_ "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/jsii" + + "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3" + "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3/cdk16625/donotimport/internal" +) + +// This type demonstrates the ability to receive a callback argument that has a type from a submodule not explicitly imported in the user's code. +// +// This checks +// that all types available in the assembly can be resolved by the runtime +// library, regardless of whether they were explicitly referenced or not. +// See: https://github.com/aws/aws-cdk/issues/16625 +// +type UnimportedSubmoduleType interface { + jsiicalc.IRandomNumberGenerator + Next() *float64 +} + +// The jsii proxy struct for UnimportedSubmoduleType +type jsiiProxy_UnimportedSubmoduleType struct { + internal.Type__jsiicalcIRandomNumberGenerator +} + +func NewUnimportedSubmoduleType(value *float64) UnimportedSubmoduleType { + _init_.Initialize() + + j := jsiiProxy_UnimportedSubmoduleType{} + + _jsii_.Create( + "jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType", + []interface{}{value}, + &j, + ) + + return &j +} + +func NewUnimportedSubmoduleType_Override(u UnimportedSubmoduleType, value *float64) { + _init_.Initialize() + + _jsii_.Create( + "jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType", + []interface{}{value}, + u, + ) +} + +// Not quite random, but it'll do. +// +// Returns: 1337 +func (u *jsiiProxy_UnimportedSubmoduleType) Next() *float64 { + var returns *float64 + + _jsii_.Invoke( + u, + "next", + nil, // no parameters + &returns, + ) + + return returns +} + + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/cdk16625/donotimport/donotimport.init.go 1`] = ` +package donotimport + +import ( + "reflect" + + _jsii_ "github.com/aws/jsii-runtime-go/runtime" +) + +func init() { + _jsii_.RegisterClass( + "jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType", + reflect.TypeOf((*UnimportedSubmoduleType)(nil)).Elem(), + []_jsii_.Member{ + _jsii_.MemberMethod{JsiiMethod: "next", GoMethod: "Next"}, + }, + func() interface{} { + j := jsiiProxy_UnimportedSubmoduleType{} + _jsii_.InitJsiiProxy(&j.Type__jsiicalcIRandomNumberGenerator) + return &j + }, + ) +} + +`; + +exports[`Generated code for "jsii-calc": /go/jsiicalc/cdk16625/donotimport/internal/types.go 1`] = ` +package internal +import ( + "github.com/aws/jsii/jsii-calc/go/jsiicalc/v3" +) +type Type__jsiicalcIRandomNumberGenerator = jsiicalc.IRandomNumberGenerator + `; exports[`Generated code for "jsii-calc": /go/jsiicalc/composition/composition.go 1`] = ` diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap index 4dc8f76a55..e223436fe6 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-java.test.ts.snap @@ -3586,6 +3586,10 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 BurriedAnonymousObject.java ┃ ┣━ 📄 Calculator.java ┃ ┣━ 📄 CalculatorProps.java + ┃ ┣━ 📁 cdk16625 + ┃ ┃ ┣━ 📄 Cdk16625.java + ┃ ┃ ┗━ 📁 donotimport + ┃ ┃ ┗━ 📄 UnimportedSubmoduleType.java ┃ ┣━ 📄 ChildStruct982.java ┃ ┣━ 📄 ClassThatImplementsTheInternalInterface.java ┃ ┣━ 📄 ClassThatImplementsThePrivateInterface.java @@ -21786,6 +21790,120 @@ public class WithPrivatePropertyInConstructor extends software.amazon.jsii.JsiiO `; +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/cdk16625/Cdk16625.java 1`] = ` +package software.amazon.jsii.tests.calculator.cdk16625; + +/** + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.cdk16625.Cdk16625") +public abstract class Cdk16625 extends software.amazon.jsii.JsiiObject { + + protected Cdk16625(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected Cdk16625(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + protected Cdk16625() { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this); + } + + /** + * Run this function to verify that everything is working as it should. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public void test() { + software.amazon.jsii.Kernel.call(this, "test", software.amazon.jsii.NativeType.VOID); + } + + /** + * Implement this functin to return \`gen.next()\`. It is extremely important that the \`donotimport\` submodule is NEVER explicitly loaded in the testing application (otherwise this test is void). + *

+ * @param gen a VERY pseudo random number generator. This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + protected abstract @org.jetbrains.annotations.NotNull java.lang.Number unwrap(final @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.IRandomNumberGenerator gen); + + /** + * A proxy class which represents a concrete javascript instance of this type. + */ + @software.amazon.jsii.Internal + private static final class Jsii$Proxy extends software.amazon.jsii.tests.calculator.cdk16625.Cdk16625 { + protected Jsii$Proxy(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + /** + * Implement this functin to return \`gen.next()\`. It is extremely important that the \`donotimport\` submodule is NEVER explicitly loaded in the testing application (otherwise this test is void). + *

+ * @param gen a VERY pseudo random number generator. This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + protected final @org.jetbrains.annotations.NotNull java.lang.Number unwrap(final @org.jetbrains.annotations.NotNull software.amazon.jsii.tests.calculator.IRandomNumberGenerator gen) { + return software.amazon.jsii.Kernel.call(this, "unwrap", software.amazon.jsii.NativeType.forClass(java.lang.Number.class), new Object[] { java.util.Objects.requireNonNull(gen, "gen is required") }); + } + } +} + +`; + +exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/cdk16625/donotimport/UnimportedSubmoduleType.java 1`] = ` +package software.amazon.jsii.tests.calculator.cdk16625.donotimport; + +/** + * This type demonstrates the ability to receive a callback argument that has a type from a submodule not explicitly imported in the user's code. + *

+ * This checks + * that all types available in the assembly can be resolved by the runtime + * library, regardless of whether they were explicitly referenced or not. + *

+ * @see https://github.com/aws/aws-cdk/issues/16625 + */ +@javax.annotation.Generated(value = "jsii-pacmak") +@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) +@software.amazon.jsii.Jsii(module = software.amazon.jsii.tests.calculator.$Module.class, fqn = "jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType") +public class UnimportedSubmoduleType extends software.amazon.jsii.JsiiObject implements software.amazon.jsii.tests.calculator.IRandomNumberGenerator { + + protected UnimportedSubmoduleType(final software.amazon.jsii.JsiiObjectRef objRef) { + super(objRef); + } + + protected UnimportedSubmoduleType(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) { + super(initializationMode); + } + + /** + * @param value This parameter is required. + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + public UnimportedSubmoduleType(final @org.jetbrains.annotations.NotNull java.lang.Number value) { + super(software.amazon.jsii.JsiiObject.InitializationMode.JSII); + software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { java.util.Objects.requireNonNull(value, "value is required") }); + } + + /** + * Not quite random, but it'll do. + *

+ * @return 1337 + */ + @software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Stable) + @Override + public @org.jetbrains.annotations.NotNull java.lang.Number next() { + return software.amazon.jsii.Kernel.call(this, "next", software.amazon.jsii.NativeType.forClass(java.lang.Number.class)); + } +} + +`; + exports[`Generated code for "jsii-calc": /java/src/main/java/software/amazon/jsii/tests/calculator/composition/CompositeOperation.java 1`] = ` package software.amazon.jsii.tests.calculator.composition; @@ -25757,6 +25875,8 @@ jsii-calc.VariadicMethod=software.amazon.jsii.tests.calculator.VariadicMethod jsii-calc.VirtualMethodPlayground=software.amazon.jsii.tests.calculator.VirtualMethodPlayground jsii-calc.VoidCallback=software.amazon.jsii.tests.calculator.VoidCallback jsii-calc.WithPrivatePropertyInConstructor=software.amazon.jsii.tests.calculator.WithPrivatePropertyInConstructor +jsii-calc.cdk16625.Cdk16625=software.amazon.jsii.tests.calculator.cdk16625.Cdk16625 +jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType=software.amazon.jsii.tests.calculator.cdk16625.donotimport.UnimportedSubmoduleType jsii-calc.composition.CompositeOperation=software.amazon.jsii.tests.calculator.composition.CompositeOperation jsii-calc.composition.CompositeOperation.CompositionStringStyle=software.amazon.jsii.tests.calculator.composition.CompositeOperation$CompositionStringStyle jsii-calc.module2530.MyClass=software.amazon.jsii.tests.calculator.module2530.MyClass diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap index ddb6eaa085..395d07c220 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap @@ -1829,6 +1829,9 @@ __all__ = [ publication.publish() +# Loading modules to ensure their types are registered with the jsii runtime library +import scope.jsii_calc_lib.custom_submodule_name + `; exports[`Generated code for "@scope/jsii-calc-lib": /python/src/scope/jsii_calc_lib/_jsii/__init__.py 1`] = ` @@ -2087,6 +2090,10 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📁 bin ┃ ┃ ┗━ 📄 calc ┃ ┗━ 📄 jsii-calc@3.20.120.jsii.tgz + ┣━ 📁 cdk16625 + ┃ ┣━ 📄 __init__.py + ┃ ┗━ 📁 donotimport + ┃ ┗━ 📄 __init__.py ┣━ 📁 composition ┃ ┗━ 📄 __init__.py ┣━ 📁 derived_class_has_no_properties @@ -2430,6 +2437,8 @@ kwargs = json.loads( "packages": [ "jsii_calc", "jsii_calc._jsii", + "jsii_calc.cdk16625", + "jsii_calc.cdk16625.donotimport", "jsii_calc.composition", "jsii_calc.derived_class_has_no_properties", "jsii_calc.interface_in_namespace_includes_classes", @@ -10195,6 +10204,40 @@ __all__ = [ publication.publish() +# Loading modules to ensure their types are registered with the jsii runtime library +import jsii_calc.cdk16625 +import jsii_calc.cdk16625.donotimport +import jsii_calc.composition +import jsii_calc.derived_class_has_no_properties +import jsii_calc.interface_in_namespace_includes_classes +import jsii_calc.interface_in_namespace_only_interface +import jsii_calc.module2530 +import jsii_calc.module2617 +import jsii_calc.module2647 +import jsii_calc.module2689 +import jsii_calc.module2689.methods +import jsii_calc.module2689.props +import jsii_calc.module2689.retval +import jsii_calc.module2689.structs +import jsii_calc.module2692 +import jsii_calc.module2692.submodule1 +import jsii_calc.module2692.submodule2 +import jsii_calc.module2700 +import jsii_calc.module2702 +import jsii_calc.nodirect +import jsii_calc.nodirect.sub1 +import jsii_calc.nodirect.sub2 +import jsii_calc.onlystatic +import jsii_calc.python_self +import jsii_calc.submodule +import jsii_calc.submodule.back_references +import jsii_calc.submodule.child +import jsii_calc.submodule.isolated +import jsii_calc.submodule.nested_submodule +import jsii_calc.submodule.nested_submodule.deeply_nested +import jsii_calc.submodule.param +import jsii_calc.submodule.returnsparam + `; exports[`Generated code for "jsii-calc": /python/src/jsii_calc/_jsii/__init__.py 1`] = ` @@ -10239,6 +10282,118 @@ __jsii_assembly__.invokeBinScript("jsii-calc", "calc", sys.argv[1:]) exports[`Generated code for "jsii-calc": /python/src/jsii_calc/_jsii/jsii-calc@3.20.120.jsii.tgz 1`] = `python/src/jsii_calc/_jsii/jsii-calc@3.20.120.jsii.tgz is a tarball`; +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/cdk16625/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from .._jsii import * + +from .. import IRandomNumberGenerator as _IRandomNumberGenerator_9643a8b9 + + +class Cdk16625( + metaclass=jsii.JSIIAbstractClass, + jsii_type="jsii-calc.cdk16625.Cdk16625", +): + def __init__(self) -> None: + jsii.create(self.__class__, self, []) + + @jsii.member(jsii_name="test") + def test(self) -> None: + '''Run this function to verify that everything is working as it should.''' + return typing.cast(None, jsii.invoke(self, "test", [])) + + @jsii.member(jsii_name="unwrap") # type: ignore[misc] + @abc.abstractmethod + def _unwrap(self, gen: _IRandomNumberGenerator_9643a8b9) -> jsii.Number: + '''Implement this functin to return \`\`gen.next()\`\`. It is extremely important that the \`\`donotimport\`\` submodule is NEVER explicitly loaded in the testing application (otherwise this test is void). + + :param gen: a VERY pseudo random number generator. + ''' + ... + + +class _Cdk16625Proxy(Cdk16625): + @jsii.member(jsii_name="unwrap") + def _unwrap(self, gen: _IRandomNumberGenerator_9643a8b9) -> jsii.Number: + '''Implement this functin to return \`\`gen.next()\`\`. It is extremely important that the \`\`donotimport\`\` submodule is NEVER explicitly loaded in the testing application (otherwise this test is void). + + :param gen: a VERY pseudo random number generator. + ''' + return typing.cast(jsii.Number, jsii.invoke(self, "unwrap", [gen])) + +# Adding a "__jsii_proxy_class__(): typing.Type" function to the abstract class +typing.cast(typing.Any, Cdk16625).__jsii_proxy_class__ = lambda : _Cdk16625Proxy + + +__all__ = [ + "Cdk16625", +] + +publication.publish() + +`; + +exports[`Generated code for "jsii-calc": /python/src/jsii_calc/cdk16625/donotimport/__init__.py 1`] = ` +import abc +import builtins +import datetime +import enum +import typing + +import jsii +import publication +import typing_extensions + +from ..._jsii import * + +from ... import IRandomNumberGenerator as _IRandomNumberGenerator_9643a8b9 + + +@jsii.implements(_IRandomNumberGenerator_9643a8b9) +class UnimportedSubmoduleType( + metaclass=jsii.JSIIMeta, + jsii_type="jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType", +): + '''This type demonstrates the ability to receive a callback argument that has a type from a submodule not explicitly imported in the user's code. + + This checks + that all types available in the assembly can be resolved by the runtime + library, regardless of whether they were explicitly referenced or not. + + :see: https://github.com/aws/aws-cdk/issues/16625 + ''' + + def __init__(self, value: jsii.Number) -> None: + ''' + :param value: - + ''' + jsii.create(self.__class__, self, [value]) + + @jsii.member(jsii_name="next") + def next(self) -> jsii.Number: + '''Not quite random, but it'll do. + + :return: 1337 + ''' + return typing.cast(jsii.Number, jsii.invoke(self, "next", [])) + + +__all__ = [ + "UnimportedSubmoduleType", +] + +publication.publish() + +`; + exports[`Generated code for "jsii-calc": /python/src/jsii_calc/composition/__init__.py 1`] = ` import abc import builtins diff --git a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap index b190dacfa4..c669dc5c8b 100644 --- a/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/jsii-tree.test.ts.snap @@ -78,6 +78,32 @@ exports[`jsii-tree --all 1`] = ` │ │ │ ├── abstract │ │ │ ├── immutable │ │ │ └── type: string + │ │ ├─┬ cdk16625 + │ │ │ ├─┬ submodules + │ │ │ │ └─┬ donotimport + │ │ │ │ └─┬ types + │ │ │ │ └─┬ class UnimportedSubmoduleType (stable) + │ │ │ │ ├── interfaces: IRandomNumberGenerator + │ │ │ │ └─┬ members + │ │ │ │ ├─┬ (value) initializer (stable) + │ │ │ │ │ └─┬ parameters + │ │ │ │ │ └─┬ value + │ │ │ │ │ └── type: number + │ │ │ │ └─┬ next() method (stable) + │ │ │ │ └── returns: number + │ │ │ └─┬ types + │ │ │ └─┬ class Cdk16625 (stable) + │ │ │ └─┬ members + │ │ │ ├── () initializer (stable) + │ │ │ ├─┬ test() method (stable) + │ │ │ │ └── returns: void + │ │ │ └─┬ unwrap(gen) method (stable) + │ │ │ ├── abstract + │ │ │ ├── protected + │ │ │ ├─┬ parameters + │ │ │ │ └─┬ gen + │ │ │ │ └── type: jsii-calc.IRandomNumberGenerator + │ │ │ └── returns: number │ │ ├─┬ composition │ │ │ └─┬ types │ │ │ ├─┬ class CompositeOperation (stable) @@ -3232,6 +3258,14 @@ exports[`jsii-tree --inheritance 1`] = ` │ │ │ ├── class ClassWithSelfKwarg │ │ │ ├── interface IInterfaceWithSelf │ │ │ └── interface StructWithSelf + │ │ ├─┬ cdk16625 + │ │ │ ├─┬ submodules + │ │ │ │ └─┬ donotimport + │ │ │ │ └─┬ types + │ │ │ │ └─┬ class UnimportedSubmoduleType + │ │ │ │ └── interfaces: IRandomNumberGenerator + │ │ │ └─┬ types + │ │ │ └── class Cdk16625 │ │ ├─┬ composition │ │ │ └─┬ types │ │ │ ├─┬ class CompositeOperation @@ -3729,6 +3763,20 @@ exports[`jsii-tree --members 1`] = ` │ │ │ └─┬ interface StructWithSelf │ │ │ └─┬ members │ │ │ └── self property + │ │ ├─┬ cdk16625 + │ │ │ ├─┬ submodules + │ │ │ │ └─┬ donotimport + │ │ │ │ └─┬ types + │ │ │ │ └─┬ class UnimportedSubmoduleType + │ │ │ │ └─┬ members + │ │ │ │ ├── (value) initializer + │ │ │ │ └── next() method + │ │ │ └─┬ types + │ │ │ └─┬ class Cdk16625 + │ │ │ └─┬ members + │ │ │ ├── () initializer + │ │ │ ├── test() method + │ │ │ └── unwrap(gen) method │ │ ├─┬ composition │ │ │ └─┬ types │ │ │ ├─┬ class CompositeOperation @@ -5164,6 +5212,9 @@ exports[`jsii-tree --signatures 1`] = ` │ ├── InterfaceInNamespaceIncludesClasses │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf + │ ├─┬ cdk16625 + │ │ └─┬ submodules + │ │ └── donotimport │ ├── composition │ ├── module2530 │ ├── module2617 @@ -5224,6 +5275,13 @@ exports[`jsii-tree --types 1`] = ` │ │ │ ├── class ClassWithSelfKwarg │ │ │ ├── interface IInterfaceWithSelf │ │ │ └── interface StructWithSelf + │ │ ├─┬ cdk16625 + │ │ │ ├─┬ submodules + │ │ │ │ └─┬ donotimport + │ │ │ │ └─┬ types + │ │ │ │ └── class UnimportedSubmoduleType + │ │ │ └─┬ types + │ │ │ └── class Cdk16625 │ │ ├─┬ composition │ │ │ └─┬ types │ │ │ ├── class CompositeOperation @@ -5585,6 +5643,9 @@ exports[`jsii-tree 1`] = ` │ ├── InterfaceInNamespaceIncludesClasses │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf + │ ├─┬ cdk16625 + │ │ └─┬ submodules + │ │ └── donotimport │ ├── composition │ ├── module2530 │ ├── module2617 diff --git a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap index 7796087001..3cfc31f733 100644 --- a/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/tree.test.ts.snap @@ -8,6 +8,9 @@ exports[`defaults 1`] = ` │ ├── InterfaceInNamespaceIncludesClasses │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf + │ ├─┬ cdk16625 + │ │ └─┬ submodules + │ │ └── donotimport │ ├── composition │ ├── module2530 │ ├── module2617 @@ -55,6 +58,9 @@ exports[`inheritance 1`] = ` │ ├── InterfaceInNamespaceIncludesClasses │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf + │ ├─┬ cdk16625 + │ │ └─┬ submodules + │ │ └── donotimport │ ├── composition │ ├── module2530 │ ├── module2617 @@ -102,6 +108,9 @@ exports[`members 1`] = ` │ ├── InterfaceInNamespaceIncludesClasses │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf + │ ├─┬ cdk16625 + │ │ └─┬ submodules + │ │ └── donotimport │ ├── composition │ ├── module2530 │ ├── module2617 @@ -219,6 +228,32 @@ exports[`showAll 1`] = ` │ │ │ ├── abstract │ │ │ ├── immutable │ │ │ └── type: string + │ │ ├─┬ cdk16625 + │ │ │ ├─┬ submodules + │ │ │ │ └─┬ donotimport + │ │ │ │ └─┬ types + │ │ │ │ └─┬ class UnimportedSubmoduleType + │ │ │ │ ├── interfaces: IRandomNumberGenerator + │ │ │ │ └─┬ members + │ │ │ │ ├─┬ (value) initializer + │ │ │ │ │ └─┬ parameters + │ │ │ │ │ └─┬ value + │ │ │ │ │ └── type: number + │ │ │ │ └─┬ next() method + │ │ │ │ └── returns: number + │ │ │ └─┬ types + │ │ │ └─┬ class Cdk16625 + │ │ │ └─┬ members + │ │ │ ├── () initializer + │ │ │ ├─┬ test() method + │ │ │ │ └── returns: void + │ │ │ └─┬ unwrap(gen) method + │ │ │ ├── abstract + │ │ │ ├── protected + │ │ │ ├─┬ parameters + │ │ │ │ └─┬ gen + │ │ │ │ └── type: jsii-calc.IRandomNumberGenerator + │ │ │ └── returns: number │ │ ├─┬ composition │ │ │ └─┬ types │ │ │ ├─┬ class CompositeOperation @@ -3359,6 +3394,9 @@ exports[`signatures 1`] = ` │ ├── InterfaceInNamespaceIncludesClasses │ ├── InterfaceInNamespaceOnlyInterface │ ├── PythonSelf + │ ├─┬ cdk16625 + │ │ └─┬ submodules + │ │ └── donotimport │ ├── composition │ ├── module2530 │ ├── module2617 @@ -3419,6 +3457,13 @@ exports[`types 1`] = ` │ │ │ ├── class ClassWithSelfKwarg │ │ │ ├── interface IInterfaceWithSelf │ │ │ └── interface StructWithSelf + │ │ ├─┬ cdk16625 + │ │ │ ├─┬ submodules + │ │ │ │ └─┬ donotimport + │ │ │ │ └─┬ types + │ │ │ │ └── class UnimportedSubmoduleType + │ │ │ └─┬ types + │ │ │ └── class Cdk16625 │ │ ├─┬ composition │ │ │ └─┬ types │ │ │ ├── class CompositeOperation diff --git a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap index 8f3bb3cfd6..f2b4fcd0ae 100644 --- a/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap +++ b/packages/jsii-reflect/test/__snapshots__/type-system.test.ts.snap @@ -155,6 +155,8 @@ Array [ "jsii-calc.VirtualMethodPlayground", "jsii-calc.VoidCallback", "jsii-calc.WithPrivatePropertyInConstructor", + "jsii-calc.cdk16625.Cdk16625", + "jsii-calc.cdk16625.donotimport.UnimportedSubmoduleType", "jsii-calc.composition.CompositeOperation", "jsii-calc.module2530.MyClass", "jsii-calc.module2617.OnlyStatics", diff --git a/tools/jsii-compliance/suite.ts b/tools/jsii-compliance/suite.ts index 6884e93b19..ba895b6706 100644 --- a/tools/jsii-compliance/suite.ts +++ b/tools/jsii-compliance/suite.ts @@ -507,5 +507,9 @@ export const suite: schema.Suite = { name: 'callbackParameterIsInterface', description: 'Validates pure interfaces can be passed to callbacks', }, + { + name: 'classCanBeUsedWhenNotExpressedlyLoaded', + description: 'Validates that types not explicitly loaded by the user can safely be returned by JS code', + } ], };