Skip to content

Commit

Permalink
fix(go): missing imports needed by base members (#2685)
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.

Additionally, if a constructor of a base class requires an import, it was also missing.

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

Fixes #2647
  • Loading branch information
Elad Ben-Israel authored Mar 14, 2021
1 parent 9562108 commit daca06f
Show file tree
Hide file tree
Showing 15 changed files with 772 additions and 39 deletions.
18 changes: 18 additions & 0 deletions packages/@scope/jsii-calc-lib/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as base from '@scope/jsii-calc-base';
import { Very } from '@scope/jsii-calc-base-of-base';

/**
* Abstract class which represents a numeric value.
Expand Down Expand Up @@ -109,5 +110,22 @@ 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 constructor(very: Very) {
very.hey();
}

public foo(obj: base.IBaseInterface): void {
obj.bar();
}
}

export * as submodule from './submodule';
export * from './duplicate-inherited-prop';
105 changes: 79 additions & 26 deletions packages/@scope/jsii-calc-lib/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"@scope/jsii-calc-lib.submodule": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 112
"line": 130
},
"targets": {
"dotnet": {
Expand Down Expand Up @@ -138,6 +138,59 @@
}
},
"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"
},
"locationInModule": {
"filename": "lib/index.ts",
"line": 121
},
"parameters": [
{
"name": "very",
"type": {
"fqn": "@scope/jsii-calc-base-of-base.Very"
}
}
]
},
"kind": "class",
"locationInModule": {
"filename": "lib/index.ts",
"line": 120
},
"methods": [
{
"docs": {
"stability": "deprecated"
},
"locationInModule": {
"filename": "lib/index.ts",
"line": 125
},
"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 @@ -245,7 +298,7 @@
"kind": "enum",
"locationInModule": {
"filename": "lib/index.ts",
"line": 97
"line": 98
},
"members": [
{
Expand Down Expand Up @@ -273,7 +326,7 @@
"kind": "interface",
"locationInModule": {
"filename": "lib/index.ts",
"line": 23
"line": 24
},
"name": "IDoublable",
"properties": [
Expand All @@ -285,7 +338,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 24
"line": 25
},
"name": "doubleValue",
"type": {
Expand All @@ -305,7 +358,7 @@
"kind": "interface",
"locationInModule": {
"filename": "lib/index.ts",
"line": 58
"line": 59
},
"methods": [
{
Expand All @@ -316,7 +369,7 @@
},
"locationInModule": {
"filename": "lib/index.ts",
"line": 62
"line": 63
},
"name": "hello",
"returns": {
Expand All @@ -342,7 +395,7 @@
"kind": "interface",
"locationInModule": {
"filename": "lib/index.ts",
"line": 108
"line": 109
},
"methods": [
{
Expand All @@ -352,7 +405,7 @@
},
"locationInModule": {
"filename": "lib/index.ts",
"line": 109
"line": 110
},
"name": "baz"
}
Expand All @@ -370,7 +423,7 @@
"kind": "interface",
"locationInModule": {
"filename": "lib/index.ts",
"line": 68
"line": 69
},
"name": "MyFirstStruct",
"properties": [
Expand All @@ -383,7 +436,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 77
"line": 78
},
"name": "anumber",
"type": {
Expand All @@ -399,7 +452,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 72
"line": 73
},
"name": "astring",
"type": {
Expand All @@ -414,7 +467,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 78
"line": 79
},
"name": "firstOptional",
"optional": true,
Expand Down Expand Up @@ -444,7 +497,7 @@
},
"locationInModule": {
"filename": "lib/index.ts",
"line": 35
"line": 36
},
"parameters": [
{
Expand All @@ -464,7 +517,7 @@
"kind": "class",
"locationInModule": {
"filename": "lib/index.ts",
"line": 30
"line": 31
},
"name": "Number",
"properties": [
Expand All @@ -476,7 +529,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 42
"line": 43
},
"name": "doubleValue",
"overrides": "@scope/jsii-calc-lib.IDoublable",
Expand All @@ -492,7 +545,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 35
"line": 36
},
"name": "value",
"overrides": "@scope/jsii-calc-lib.NumericValue",
Expand All @@ -515,7 +568,7 @@
"kind": "class",
"locationInModule": {
"filename": "lib/index.ts",
"line": 6
"line": 7
},
"methods": [
{
Expand All @@ -525,7 +578,7 @@
},
"locationInModule": {
"filename": "lib/index.ts",
"line": 15
"line": 16
},
"name": "toString",
"returns": {
Expand All @@ -546,7 +599,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 10
"line": 11
},
"name": "value",
"type": {
Expand All @@ -568,7 +621,7 @@
"kind": "class",
"locationInModule": {
"filename": "lib/index.ts",
"line": 50
"line": 51
},
"methods": [
{
Expand All @@ -579,7 +632,7 @@
},
"locationInModule": {
"filename": "lib/index.ts",
"line": 51
"line": 52
},
"name": "toString",
"overrides": "@scope/jsii-calc-lib.NumericValue",
Expand All @@ -603,7 +656,7 @@
"kind": "interface",
"locationInModule": {
"filename": "lib/index.ts",
"line": 84
"line": 85
},
"name": "StructWithOnlyOptionals",
"properties": [
Expand All @@ -616,7 +669,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 88
"line": 89
},
"name": "optional1",
"optional": true,
Expand All @@ -632,7 +685,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 89
"line": 90
},
"name": "optional2",
"optional": true,
Expand All @@ -648,7 +701,7 @@
"immutable": true,
"locationInModule": {
"filename": "lib/index.ts",
"line": 90
"line": 91
},
"name": "optional3",
"optional": true,
Expand Down Expand Up @@ -877,5 +930,5 @@
}
},
"version": "0.0.0",
"fingerprint": "6We+OU9YxfTRfwXErreAyzcH2dVH29FgV8eiBRjowAY="
"fingerprint": "yaW4nEkJcW4ZyHTJGV9YSAtkrzeBBoXkDffMJBD8dGQ="
}
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';
}
}
Loading

0 comments on commit daca06f

Please sign in to comment.