Skip to content

Commit

Permalink
fix(go): embedded bases may conflict with member names (#2703)
Browse files Browse the repository at this point in the history
When we generate proxy structs in Go (for classes or interfaces), we embed the base types (base class or interfaces) in the struct. If the base type has a name that is the same as a member of the hosting type, there will be a conflict.

To solve this, we create a unique type alias for each base interface we want to embed.

Fixes #2702
  • Loading branch information
Elad Ben-Israel committed Mar 17, 2021
1 parent e6ca054 commit 3594ad7
Show file tree
Hide file tree
Showing 16 changed files with 1,374 additions and 119 deletions.
1 change: 1 addition & 0 deletions packages/jsii-calc/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * as nodirect from './no-direct-types';
export * as module2647 from './module2647';
export * as module2617 from './module2617';
export * as module2689 from './module2689';
export * as module2702 from './module2702';
export * as module2692 from './module2692';
export * as module2530 from './module2530';
export * as module2700 from './module2700';
32 changes: 32 additions & 0 deletions packages/jsii-calc/lib/module2702/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// member has the same name as a base class
// @see https://github.com/aws/jsii/issues/2702

import { Base, IBaseInterface } from '@scope/jsii-calc-base';

export class Class1 extends Base {
public base() {
return;
}
}

export class Class2 extends Base {
public readonly base = 'hello';
}

export class Class3 implements IBaseInterface {
public bar(): void {
return;
}

public foo(): void {
return;
}

public iBaseInterface() {
return;
}
}

export interface IFoo extends IBaseInterface {
readonly iBaseInterface: string;
}
164 changes: 160 additions & 4 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
"jsii-calc.module2530": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 18
"line": 19
}
},
"jsii-calc.module2617": {
Expand Down Expand Up @@ -262,7 +262,7 @@
"jsii-calc.module2692": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 17
"line": 18
}
},
"jsii-calc.module2692.submodule1": {
Expand All @@ -280,7 +280,13 @@
"jsii-calc.module2700": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 19
"line": 20
}
},
"jsii-calc.module2702": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 17
}
},
"jsii-calc.nodirect": {
Expand Down Expand Up @@ -14962,6 +14968,156 @@
}
]
},
"jsii-calc.module2702.Class1": {
"assembly": "jsii-calc",
"base": "@scope/jsii-calc-base.Base",
"docs": {
"stability": "stable"
},
"fqn": "jsii-calc.module2702.Class1",
"initializer": {},
"kind": "class",
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 6
},
"methods": [
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 7
},
"name": "base"
}
],
"name": "Class1",
"namespace": "module2702"
},
"jsii-calc.module2702.Class2": {
"assembly": "jsii-calc",
"base": "@scope/jsii-calc-base.Base",
"docs": {
"stability": "stable"
},
"fqn": "jsii-calc.module2702.Class2",
"initializer": {},
"kind": "class",
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 12
},
"name": "Class2",
"namespace": "module2702",
"properties": [
{
"docs": {
"stability": "stable"
},
"immutable": true,
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 13
},
"name": "base",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.module2702.Class3": {
"assembly": "jsii-calc",
"docs": {
"stability": "stable"
},
"fqn": "jsii-calc.module2702.Class3",
"initializer": {
"docs": {
"stability": "stable"
}
},
"interfaces": [
"@scope/jsii-calc-base.IBaseInterface"
],
"kind": "class",
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 16
},
"methods": [
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 17
},
"name": "bar",
"overrides": "@scope/jsii-calc-base.IBaseInterface"
},
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 21
},
"name": "foo",
"overrides": "@scope/jsii-calc-base-of-base.IVeryBaseInterface"
},
{
"docs": {
"stability": "stable"
},
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 25
},
"name": "iBaseInterface"
}
],
"name": "Class3",
"namespace": "module2702"
},
"jsii-calc.module2702.IFoo": {
"assembly": "jsii-calc",
"docs": {
"stability": "stable"
},
"fqn": "jsii-calc.module2702.IFoo",
"interfaces": [
"@scope/jsii-calc-base.IBaseInterface"
],
"kind": "interface",
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 30
},
"name": "IFoo",
"namespace": "module2702",
"properties": [
{
"abstract": true,
"docs": {
"stability": "stable"
},
"immutable": true,
"locationInModule": {
"filename": "lib/module2702/index.ts",
"line": 31
},
"name": "iBaseInterface",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.nodirect.sub1.TypeFromSub1": {
"assembly": "jsii-calc",
"docs": {
Expand Down Expand Up @@ -15718,5 +15874,5 @@
}
},
"version": "3.20.120",
"fingerprint": "0UwgWtQxMTELv9VFLdPFtg1Zv/tSVnARqKIjCAhYAgg="
"fingerprint": "qsiNdf02KvRlGy6cULMMyEknbuVVEoKtzWVsTGz72OA="
}
Loading

0 comments on commit 3594ad7

Please sign in to comment.