-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(jsii-go): use reflect to resolve overriden methods #2780
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
24fb014
use reflect to resolve overriden methods, per issue #2768
yglcode 3cef5c0
tiny formatting fixes
RomainMuller 7feff0c
added entry in contributors hall of fame
RomainMuller aeb17c6
update error msg based on review and clean up code
yglcode c3321ef
update documentation pages
RomainMuller 28c1f65
Merge branch 'main' into reflect-overriden-methods
RomainMuller 8318b62
simplify handling of local.go.mod around error handling (in hopes it …
RomainMuller 604bfe9
Merge branch 'main' into reflect-overriden-methods
mergify[bot] 9a8db68
clarify logging a little
RomainMuller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/@jsii/go-runtime/jsii-runtime-go/overrides_reflect_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package jsii | ||
|
||
import ( | ||
"reflect" | ||
"sort" | ||
"testing" | ||
) | ||
|
||
type IFace interface { | ||
M1() | ||
M2() | ||
M3() | ||
} | ||
|
||
type Base struct { | ||
X, Y int | ||
} | ||
|
||
func (b *Base) M1() {} | ||
func (b *Base) M2() {} | ||
func (b *Base) M3() {} | ||
|
||
type D1 struct { | ||
*Base | ||
} | ||
|
||
func (d *D1) M1() {} | ||
|
||
func (d *D1) X1() {} | ||
|
||
type D2 struct { | ||
Name string | ||
IFace | ||
} | ||
|
||
func (d *D2) M2() {} | ||
|
||
func (d *D2) X2() {} | ||
|
||
func TestOverrideReflection(t *testing.T) { | ||
testCases := [...]struct { | ||
//overriding instance | ||
val interface{} | ||
//instance overriding methods | ||
methods []string | ||
}{ | ||
{&Base{}, []string(nil)}, | ||
{&D1{&Base{}}, []string{"M1", "X1"}}, | ||
{&D2{Name: "abc", IFace: &D1{&Base{}}}, []string{"M1", "X1", "M2", "X2"}}, | ||
} | ||
for _, tc := range testCases { | ||
sort.Slice(tc.methods, func(i, j int) bool { | ||
return tc.methods[i] < tc.methods[j] | ||
}) | ||
} | ||
for _, tc := range testCases { | ||
methods := getMethodOverrides(tc.val, "Base") | ||
sort.Slice(methods, func(i, j int) bool { | ||
return methods[i] < methods[j] | ||
}) | ||
if !reflect.DeepEqual(methods, tc.methods) { | ||
t.Errorf("expect: %v, got: %v", tc.methods, methods) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.