Skip to content

Commit

Permalink
fix(go): protected property accessors missing (#2738)
Browse files Browse the repository at this point in the history
Not sure if the original issue was referring to protected *methods* as well as properties, but turns out protected methods are already treated as public one. 

So this PR just fixes the handling of protected properties, as well as adjusts the compliance tests.  

Fixes #2673

---

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
iliapolo authored Mar 24, 2021
1 parent 2ba2ec4 commit 94c799a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
6 changes: 3 additions & 3 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 (73.50%) | Dotnet | Python |
| number | test | java (100.00%) | golang (75.21%) | 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 Down Expand Up @@ -55,7 +55,7 @@ This section details the current state of each language binding with respect to
| 46 | useNestedStruct | 🟢 | 🟢 |||
| 47 | testFluentApiWithDerivedClasses | 🟢 | 🟢 |||
| 48 | interfacesCanBeUsedTransparently_WhenAddedToJsiiType | 🟢 | 🟢 |||
| 49 | canOverrideProtectedGetter | 🟢 | [🔴](https://github.com/aws/jsii/issues/2673) |||
| 49 | canOverrideProtectedGetter | 🟢 | 🟢 |||
| 50 | getAndSetEnumValues | 🟢 | 🟢 |||
| 51 | structs_nonOptionalequals | 🟢 | 🟢 |||
| 52 | testInterfaceParameter | 🟢 | 🟢 |||
Expand All @@ -66,7 +66,7 @@ This section details the current state of each language binding with respect to
| 57 | eraseUnsetDataValues | 🟢 | 🟢 |||
| 58 | maps | 🟢 | 🟢 |||
| 59 | structs_containsNullChecks | 🟢 | [🔴](https://github.com/aws/jsii/issues/2672) |||
| 60 | canOverrideProtectedSetter | 🟢 | [🔴](https://github.com/aws/jsii/issues/2673) |||
| 60 | canOverrideProtectedSetter | 🟢 | 🟢 |||
| 61 | asyncOverrides_callAsyncMethod | 🟢 | [🔴](https://github.com/aws/jsii/issues/2670) |||
| 62 | nodeStandardLibrary | 🟢 | [🔴](https://github.com/aws/jsii/issues/2670) |||
| 63 | dates | 🟢 | 🟢 |||
Expand Down
26 changes: 19 additions & 7 deletions packages/@jsii/go-runtime-test/project/compliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (suite *ComplianceSuite) TestEqualsIsResistantToPropertyShadowingResultVari
}

type overridableProtectedMemberDerived struct {
calc.OverridableProtectedMember `overrides:"OverrideReadOnly,OverrideReadeWrite"`
calc.OverridableProtectedMember `overrides:"OverrideReadOnly,OverrideReadWrite"`
}

func newOverridableProtectedMemberDerived() *overridableProtectedMemberDerived {
Expand All @@ -360,13 +360,11 @@ func (x *overridableProtectedMemberDerived) OverrideReadOnly() *string {
return jsii.String("Cthulhu ")
}

func (x *overridableProtectedMemberDerived) OverrideReadeWrite() *string {
func (x *overridableProtectedMemberDerived) OverrideReadWrite() *string {
return jsii.String("Fhtagn!")
}

func (suite *ComplianceSuite) TestCanOverrideProtectedGetter() {
suite.FailTest("unable to access protected members", "https://github.com/aws/jsii/issues/2673")

assert := suite.Assert()
overridden := newOverridableProtectedMemberDerived()
assert.Equal("Cthulhu Fhtagn!", *overridden.ValueFromProtected())
Expand Down Expand Up @@ -718,14 +716,28 @@ func (suite *ComplianceSuite) TestAbstractMembersAreCorrectlyHandled() {
}

func (suite *ComplianceSuite) TestCanOverrideProtectedSetter() {
suite.FailTest("unable to access protected members", "https://github.com/aws/jsii/issues/2673")
assert := suite.Assert()
challenge := "Bazzzzzzzzzzzaar..."
overridden := myOverridableProtectedMember{calc.NewOverridableProtectedMember()}
overridden := newTestCanOverrideProtectedSetterOverridableProtectedMember()
overridden.SwitchModes()
assert.Equal(challenge, overridden.ValueFromProtected())
assert.Equal(challenge, *overridden.ValueFromProtected())
}

type TestCanOverrideProtectedSetterOverridableProtectedMember struct {
calc.OverridableProtectedMember `overrides:"OverrideReadWrite"`
}

func (x TestCanOverrideProtectedSetterOverridableProtectedMember) SetOverrideReadWrite(val *string) {
x.OverridableProtectedMember.SetOverrideReadWrite(jsii.String(fmt.Sprintf("zzzzzzzzz%s", *val)))
}

func newTestCanOverrideProtectedSetterOverridableProtectedMember() *TestCanOverrideProtectedSetterOverridableProtectedMember {
m := TestCanOverrideProtectedSetterOverridableProtectedMember{}
calc.NewOverridableProtectedMember_Override(&m)
return &m
}


func (suite *ComplianceSuite) TestObjRefsAreLabelledUsingWithTheMostCorrectType() {
assert := suite.Assert()

Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/lib/targets/go/types/type-member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class GoProperty implements GoTypeMember {

public emitSetterDecl(context: EmitContext) {
const { code } = context;
if (!this.property.protected && !this.immutable) {
if (!this.immutable) {
code.line(`Set${this.name}(val ${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 94c799a

Please sign in to comment.