Skip to content

Commit

Permalink
fix(go): missing imports needed by reimplemented members
Browse files Browse the repository at this point in the history
Go pacmak will reimplement methods and properties in case the class has more than a single "base" (interface/class). The Go code generator failed to include these members when determining which imports to generate.

Add a calc test fixture to verify (failed without this change).

Fixes #2647
  • Loading branch information
Elad Ben-Israel committed Mar 14, 2021
1 parent 45b527c commit d73e69e
Show file tree
Hide file tree
Showing 10 changed files with 614 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/@scope/jsii-calc-lib/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,18 @@ export interface IThreeLevelsInterface extends base.IBaseInterface {
baz(): void;
}

/**
* A base class for testing #2647. The method `foo` has a parameter that uses a type
* from a dependent module. Since Go "reimplments" this method, it will also need
* to include an "import" statement for the calc-base module.
*
* @see https://github.com/aws/jsii/issues/2647
*/
export class BaseFor2647 {
public foo(obj: base.IBaseInterface): void {
obj.bar();
}
}

export * as submodule from './submodule';
export * from './duplicate-inherited-prop';
45 changes: 43 additions & 2 deletions packages/@scope/jsii-calc-lib/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"@scope/jsii-calc-lib.submodule": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 112
"line": 125
},
"targets": {
"dotnet": {
Expand Down Expand Up @@ -133,6 +133,47 @@
}
},
"types": {
"@scope/jsii-calc-lib.BaseFor2647": {
"assembly": "@scope/jsii-calc-lib",
"docs": {
"remarks": "The method `foo` has a parameter that uses a type\nfrom a dependent module. Since Go \"reimplments\" this method, it will also need\nto include an \"import\" statement for the calc-base module.",
"see": "https://github.com/aws/jsii/issues/2647",
"stability": "deprecated",
"summary": "A base class for testing #2647."
},
"fqn": "@scope/jsii-calc-lib.BaseFor2647",
"initializer": {
"docs": {
"stability": "deprecated"
}
},
"kind": "class",
"locationInModule": {
"filename": "lib/index.ts",
"line": 119
},
"methods": [
{
"docs": {
"stability": "deprecated"
},
"locationInModule": {
"filename": "lib/index.ts",
"line": 120
},
"name": "foo",
"parameters": [
{
"name": "obj",
"type": {
"fqn": "@scope/jsii-calc-base.IBaseInterface"
}
}
]
}
],
"name": "BaseFor2647"
},
"@scope/jsii-calc-lib.DiamondLeft": {
"assembly": "@scope/jsii-calc-lib",
"datatype": true,
Expand Down Expand Up @@ -872,5 +913,5 @@
}
},
"version": "0.0.0",
"fingerprint": "YlmxPtOusVTgKe2YUzZDpB4UnmnU3zZ0UUdXwSDcgOo="
"fingerprint": "pW043fHp8icTWympphJfAKrI/5PT2F1nZyyNNyEmTjM="
}
1 change: 1 addition & 0 deletions packages/jsii-calc/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './submodules';
export * as submodule from './submodule';
export * as onlystatic from './only-static';
export * as nodirect from './no-direct-types';
export * as module2647 from './module2647';
17 changes: 17 additions & 0 deletions packages/jsii-calc/lib/module2647/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IFriendly, BaseFor2647 } from '@scope/jsii-calc-lib';

/**
* This class falls into the category of "multiple bases" from a different
* module from a go code gen perspective.
*
* @see https://github.com/aws/jsii/issues/2647
*/
export class ExtendAndImplement extends BaseFor2647 implements IFriendly {
public localMethod() {
return 'hi';
}

public hello() {
return 'extends and implements';
}
}
69 changes: 67 additions & 2 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"@scope/jsii-calc-lib.submodule": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 112
"line": 125
},
"targets": {
"dotnet": {
Expand Down Expand Up @@ -206,6 +206,12 @@
"line": 142
}
},
"jsii-calc.module2647": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 14
}
},
"jsii-calc.nodirect": {
"locationInModule": {
"filename": "lib/index.ts",
Expand Down Expand Up @@ -14114,6 +14120,65 @@
"name": "CompositionStringStyle",
"namespace": "composition.CompositeOperation"
},
"jsii-calc.module2647.ExtendAndImplement": {
"assembly": "jsii-calc",
"base": "@scope/jsii-calc-lib.BaseFor2647",
"docs": {
"see": "https://github.com/aws/jsii/issues/2647",
"stability": "stable",
"summary": "This class falls into the category of \"multiple bases\" from a different module from a go code gen perspective."
},
"fqn": "jsii-calc.module2647.ExtendAndImplement",
"initializer": {
"docs": {
"stability": "deprecated"
}
},
"interfaces": [
"@scope/jsii-calc-lib.IFriendly"
],
"kind": "class",
"locationInModule": {
"filename": "lib/module2647/index.ts",
"line": 9
},
"methods": [
{
"docs": {
"stability": "stable",
"summary": "(deprecated) Say hello!"
},
"locationInModule": {
"filename": "lib/module2647/index.ts",
"line": 14
},
"name": "hello",
"overrides": "@scope/jsii-calc-lib.IFriendly",
"returns": {
"type": {
"primitive": "string"
}
}
},
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "lib/module2647/index.ts",
"line": 10
},
"name": "localMethod",
"returns": {
"type": {
"primitive": "string"
}
}
}
],
"name": "ExtendAndImplement",
"namespace": "module2647"
},
"jsii-calc.nodirect.sub1.TypeFromSub1": {
"assembly": "jsii-calc",
"docs": {
Expand Down Expand Up @@ -14870,5 +14935,5 @@
}
},
"version": "3.20.120",
"fingerprint": "rH6rK3iHNatb4ojll7sd8rvJ4k/89Kybg89FRd96Hno="
"fingerprint": "61fXjiesh/E+ejTgQ0gXmmToVljlc8IbNsEz4o5DDGY="
}
2 changes: 2 additions & 0 deletions packages/jsii-pacmak/lib/targets/go/types/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ export class GoClass extends GoType {
...this.properties,
...this.staticMethods,
...this.staticProperties,
...(this.reimplementedMethods ?? []),
...(this.reimplementedProperties ?? []),
];
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d73e69e

Please sign in to comment.