From 74d0d9999d6381ef8bec36a45141380f190e26b9 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Tue, 23 Mar 2021 01:30:23 +0100 Subject: [PATCH] fix(go): missing setter for R/W interface properties (#2731) Adding the missing code generation for interface properties that are writable. Previously, only the reader was generated. Fixes #2665 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0 --- .../content/specification/6-compliance-report.md | 8 ++++---- .../go-runtime-test/project/compliance_test.go | 13 ++++--------- packages/@jsii/go-runtime-test/project/go.sum | 6 ------ .../jsii-pacmak/lib/targets/go/types/interface.ts | 7 +++++++ .../__snapshots__/target-go.test.ts.snap | 14 ++++++++++++++ 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/gh-pages/content/specification/6-compliance-report.md b/gh-pages/content/specification/6-compliance-report.md index 9014b55c41..ca798d0e96 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 (100.00%) | golang (67.52%) | Dotnet | Python | +| number | test | java (100.00%) | golang (70.09%) | 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") | 🟢 | 🟢 | ⭕ | ⭕ | @@ -21,8 +21,8 @@ This section details the current state of each language binding with respect to | 12 | [classesCanSelfReferenceDuringClassInitialization]("Classes can reference other classes during initialization") | 🟢 | 🟢 | ⭕ | ⭕ | | 13 | [canObtainStructReferenceWithOverloadedSetter]("A class with a settable property of a union type can be returned from the kernel") | 🟢 | 🟢 | ⭕ | ⭕ | | 14 | [callbacksCorrectlyDeserializeArguments]("Runtime properly deserializes callback arguments from the kernel") | 🟢 | 🟢 | ⭕ | ⭕ | -| 15 | [canUseInterfaceSetters]("Read-write properties generate the corresponding setters in the target language") | 🟢 | [🔴](https://github.com/aws/jsii/issues/2665) | ⭕ | ⭕ | -| 16 | [propertyOverrides_interfaces]("Target language can override properties of host interfaces") | 🟢 | [🔴](https://github.com/aws/jsii/issues/2665) | ⭕ | ⭕ | +| 15 | [canUseInterfaceSetters]("Read-write properties generate the corresponding setters in the target language") | 🟢 | 🟢 | ⭕ | ⭕ | +| 16 | [propertyOverrides_interfaces]("Target language can override properties of host interfaces") | 🟢 | 🟢 | ⭕ | ⭕ | | 17 | syncOverrides_callsSuper | 🟢 | 🟢 | ⭕ | ⭕ | | 18 | [testJsiiAgent]("Asserts the correct value of the JSII_AGENT env variable for the kernel process") | 🟢 | 🟢 | ⭕ | ⭕ | | 19 | [doNotOverridePrivates_method_private]("Non public methods on the guest class do not override methods in the host class") | 🟢 | 🟢 | ⭕ | ⭕ | @@ -31,7 +31,7 @@ This section details the current state of each language binding with respect to | 22 | [primitiveTypes]("All Primitive types are set and read with their respective types") | 🟢 | [🔴](https://github.com/aws/jsii/issues/2659) | ⭕ | ⭕ | | 23 | [reservedKeywordsAreSlugifiedInClassProperties]("TS code that uses reserved words as class property names get slugified so it is usable in the target language") | 🟢 | ⚪ | ⭕ | ⭕ | | 24 | [objectIdDoesNotGetReallocatedWhenTheConstructorPassesThisOut]("Ensure the JSII kernel can pass 'this' out to JSII remotes from within the constructor") | 🟢 | 🟢 | ⭕ | ⭕ | -| 25 | [interfaceBuilder]("Seems to be a duplicate of 'propertyOverrides_interfaces'?") | 🟢 | [🔴](https://github.com/aws/jsii/issues/2665) | ⭕ | ⭕ | +| 25 | [interfaceBuilder]("Seems to be a duplicate of 'propertyOverrides_interfaces'?") | 🟢 | 🟢 | ⭕ | ⭕ | | 26 | unionTypes | 🟢 | [🔴](https://github.com/aws/jsii/issues/2686) | ⭕ | ⭕ | | 27 | arrays | 🟢 | [🔴](https://github.com/aws/jsii/issues/2686) | ⭕ | ⭕ | | 28 | staticMapInClassCannotBeModified | 🟢 | ⚪ | ⭕ | ⭕ | diff --git a/packages/@jsii/go-runtime-test/project/compliance_test.go b/packages/@jsii/go-runtime-test/project/compliance_test.go index f51ac9543c..1170864106 100644 --- a/packages/@jsii/go-runtime-test/project/compliance_test.go +++ b/packages/@jsii/go-runtime-test/project/compliance_test.go @@ -529,9 +529,7 @@ func (suite *ComplianceSuite) TestCanUseInterfaceSetters() { assert := suite.Assert() obj := calc.ObjectWithPropertyProvider_Provide() - suite.FailTest("Setter are not generated for read-write properties", "https://github.com/aws/jsii/issues/2665") - - // obj.SetProperty("New Value") + obj.SetProperty(jsii.String("New Value")) assert.True(*obj.WasSet()) } @@ -542,8 +540,7 @@ func (suite *ComplianceSuite) TestPropertyOverrides_Interfaces() { interact := calc.NewUsesInterfaceWithProperties(&interfaceWithProps) assert.Equal("READ_ONLY_STRING", *interact.JustRead()) - suite.FailTest("Not sure. Most likely related to the missing setters on interfaces", "https://github.com/aws/jsii/issues/2665") - assert.Equal("Hello!?", interact.WriteAndRead(jsii.String("Hello"))) + assert.Equal("Hello!?", *interact.WriteAndRead(jsii.String("Hello"))) } type TestPropertyOverridesInterfacesIInterfaceWithProperties struct { @@ -561,9 +558,8 @@ func (i *TestPropertyOverridesInterfacesIInterfaceWithProperties) ReadWriteStrin return jsii.String(result) } -// Note this method is not currently part of the generated interface for some reason (https://github.com/aws/jsii/issues/2665). -func (i *TestPropertyOverridesInterfacesIInterfaceWithProperties) SetReadWriteString(value string) { - newVal := value + "!" +func (i *TestPropertyOverridesInterfacesIInterfaceWithProperties) SetReadWriteString(value *string) { + newVal := *value + "!" i.x = &newVal } @@ -1355,7 +1351,6 @@ func (suite *ComplianceSuite) TestInterfaceBuilder() { interact := calc.NewUsesInterfaceWithProperties(&TestInterfaceBuilderIInterfaceWithProperties{value: jsii.String("READ_WRITE")}) assert.Equal("READ_ONLY", *interact.JustRead()) - suite.FailTest("Not sure. Most likely related to the missing setters on interfaces", "https://github.com/aws/jsii/issues/2665") assert.Equal("Hello", *interact.WriteAndRead(jsii.String("Hello"))) } diff --git a/packages/@jsii/go-runtime-test/project/go.sum b/packages/@jsii/go-runtime-test/project/go.sum index 3c6e99ae33..ceb0e37170 100644 --- a/packages/@jsii/go-runtime-test/project/go.sum +++ b/packages/@jsii/go-runtime-test/project/go.sum @@ -4,15 +4,12 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/yuin/goldmark v1.2.1 h1:ruQGxdhGHe7FWOJPT0mKs5+pD2Xs1Bm/kdGlHO04FmM= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= @@ -21,10 +18,8 @@ golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -32,7 +27,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= diff --git a/packages/jsii-pacmak/lib/targets/go/types/interface.ts b/packages/jsii-pacmak/lib/targets/go/types/interface.ts index 54165f6ca8..69c527400c 100644 --- a/packages/jsii-pacmak/lib/targets/go/types/interface.ts +++ b/packages/jsii-pacmak/lib/targets/go/types/interface.ts @@ -207,6 +207,13 @@ class InterfaceProperty extends GoProperty { public emit({ code, documenter }: EmitContext) { documenter.emit(this.property.docs); code.line(`${this.name}() ${this.returnType}`); + + if (!this.property.immutable) { + documenter.emit(this.property.docs); + code.line( + `Set${this.name}(${this.name[0].toLowerCase()} ${this.returnType})`, + ); + } } } 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 b6a2ec1f24..da8c244e0a 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 @@ -7203,6 +7203,7 @@ func (j *jsiiProxy_IAnonymouslyImplementMe) Value() *float64 { type IAnotherPublicInterface interface { A() *string + SetA(a *string) } // The jsii proxy for IAnotherPublicInterface @@ -7287,6 +7288,8 @@ type IDeprecatedInterface interface { Method() // Deprecated: could be better MutableProperty() *float64 + // Deprecated: could be better + SetMutableProperty(m *float64) } // The jsii proxy for IDeprecatedInterface @@ -7326,6 +7329,8 @@ type IExperimentalInterface interface { Method() // Experimental. MutableProperty() *float64 + // Experimental. + SetMutableProperty(m *float64) } // The jsii proxy for IExperimentalInterface @@ -7362,6 +7367,7 @@ func (j *jsiiProxy_IExperimentalInterface) SetMutableProperty(val *float64) { type IExtendsPrivateInterface interface { MoreThings() *[]*string Private() *string + SetPrivate(p *string) } // The jsii proxy for IExtendsPrivateInterface @@ -7400,6 +7406,7 @@ func (j *jsiiProxy_IExtendsPrivateInterface) SetPrivate(val *string) { type IExternalInterface interface { Method() MutableProperty() *float64 + SetMutableProperty(m *float64) } // The jsii proxy for IExternalInterface @@ -7619,6 +7626,7 @@ func (i *jsiiProxy_IInterfaceWithOptionalMethodArguments) Hello(arg1 *string, ar type IInterfaceWithProperties interface { ReadOnlyString() *string ReadWriteString() *string + SetReadWriteString(r *string) } // The jsii proxy for IInterfaceWithProperties @@ -7657,6 +7665,7 @@ func (j *jsiiProxy_IInterfaceWithProperties) SetReadWriteString(val *string) { type IInterfaceWithPropertiesExtension interface { IInterfaceWithProperties Foo() *float64 + SetFoo(f *float64) } // The jsii proxy for IInterfaceWithPropertiesExtension @@ -7774,6 +7783,7 @@ type jsiiProxy_IJsii496 struct { type IMutableObjectLiteral interface { Value() *string + SetValue(v *string) } // The jsii proxy for IMutableObjectLiteral @@ -7802,7 +7812,9 @@ func (j *jsiiProxy_IMutableObjectLiteral) SetValue(val *string) { type INonInternalInterface interface { IAnotherPublicInterface B() *string + SetB(b *string) C() *string + SetC(c *string) } // The jsii proxy for INonInternalInterface @@ -7850,6 +7862,7 @@ func (j *jsiiProxy_INonInternalInterface) SetC(val *string) { type IObjectWithProperty interface { WasSet() *bool Property() *string + SetProperty(p *string) } // The jsii proxy for IObjectWithProperty @@ -8056,6 +8069,7 @@ func (j *jsiiProxy_IReturnsNumber) NumberProp() scopejsiicalclib.Number { type IStableInterface interface { Method() MutableProperty() *float64 + SetMutableProperty(m *float64) } // The jsii proxy for IStableInterface