-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
linter, executor: fix the constructor
linter and add it to BaseExecutor/BaseExecutorV2
#56485
Conversation
@@ -276,6 +277,8 @@ func newExecutorKillerHandler(handler signalHandler) executorKillerHandler { | |||
|
|||
// BaseExecutorV2 is a simplified version of `BaseExecutor`, which doesn't contain a full session context | |||
type BaseExecutorV2 struct { | |||
_ constructor.Constructor `ctor:"NewBaseExecutorV2,BuildNewBaseExecutorV2"` |
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.
@yibin87 PTAL. It can guarantee that BaseExecutorV2
will not be manually initialized except in NewBaseExecutorV2
and BuildNewBaseExecutorV2
.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #56485 +/- ##
================================================
+ Coverage 73.3685% 75.6763% +2.3078%
================================================
Files 1624 1648 +24
Lines 448117 462949 +14832
================================================
+ Hits 328777 350343 +21566
+ Misses 99198 91374 -7824
- Partials 20142 21232 +1090
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
LGTM
aaf1b81
to
1ca5990
Compare
Signed-off-by: Yang Keao <[email protected]>
1ca5990
to
5c052a9
Compare
@@ -82,7 +90,7 @@ func getConstructorList(t types.Type) []string { | |||
} | |||
|
|||
if fieldStruct, ok := named.Underlying().(*types.Struct); ok { | |||
ctors = append(ctors, getConstructorList(fieldStruct)...) | |||
ctors = append(ctors, getConstructorList(fieldStruct, nil)...) |
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.
Let me clarify. In this PR you added ignoreFields
to getConstructorList
to skip some fields when recursively process struct
. And I think this line is the cause of recursively processing struct
. We don't need this line because WithStack
still access the member of struct
. Can we delete this line and delete the ignoreFields
logic of getConstructorList
?
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.
getConstructorList
should be called recursively to avoid implicitly constructing the embedded structs:
type A struct { _ constructor.Constructor `ctor:"NewA"`}
type B struct {A}
type C struct {B}
var c C
The var c C
is not allowed, because it will implicitly create a A
outside of its constructor. The WithStack
can do nothing for it as it doesn't appear in the AST.
The ignoreFields
is added in this PR to allow this situation:
func XFunc() {
b := B {
A: NewA()
}
}
Preivously, the getConstructorList()
of B
will return NewA
, and linter will give an error because it's constructed in XFunc
. However, it should be allowed as the A
is actually not constructed in XFunc
, but in NewA
.
/retest |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hawkingrei, lance6716, yibin87 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What problem does this PR solve?
Issue Number: close #56484
Problem Summary:
What changed and how does it work?
constructor
annotation to the structBaseExecutor/BaseExecutorV2
to avoid constructing the struct unexpectedly.constructor
linter, and correct some behaviors.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.