Skip to content

Commit

Permalink
fix(go): missing setter for R/W interface properties (#2731)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RomainMuller authored Mar 23, 2021
1 parent c79a346 commit 74d0d99
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
8 changes: 4 additions & 4 deletions gh-pages/content/specification/6-compliance-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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") | 🟢 | 🟢 |||
Expand All @@ -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") | 🟢 | 🟢 |||
Expand All @@ -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 | 🟢 ||||
Expand Down
13 changes: 4 additions & 9 deletions packages/@jsii/go-runtime-test/project/compliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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")))
}

Expand Down
6 changes: 0 additions & 6 deletions packages/@jsii/go-runtime-test/project/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -21,18 +18,15 @@ 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=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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=
Expand Down
7 changes: 7 additions & 0 deletions packages/jsii-pacmak/lib/targets/go/types/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`,
);
}
}
}

Expand Down

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

0 comments on commit 74d0d99

Please sign in to comment.