Skip to content

Commit

Permalink
add to unit tests and add assignment flow
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalmahajan15 committed Nov 30, 2023
1 parent 511a181 commit 8ee8677
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 17 additions & 8 deletions annotation/consume_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,15 +886,17 @@ func (a *ArgPassDeep) Prestring() Prestring {
switch key := a.Ann.(type) {
case *ParamAnnotationKey:
return ArgPassPrestring{
ParamName: key.MinimalString(),
FuncName: key.FuncDecl.Name(),
Location: "",
ParamName: key.MinimalString(),
FuncName: key.FuncDecl.Name(),
Location: "",
AssignmentStr: a.assignmentFlow.String(),
}
case *CallSiteParamAnnotationKey:
return ArgPassPrestring{
ParamName: key.MinimalString(),
FuncName: key.FuncDecl.Name(),
Location: key.Location.String(),
ParamName: key.MinimalString(),
FuncName: key.FuncDecl.Name(),
Location: key.Location.String(),
AssignmentStr: a.assignmentFlow.String(),
}
default:
panic(fmt.Sprintf(
Expand All @@ -908,7 +910,8 @@ type ArgPassDeepPrestring struct {
FuncName string
// Location points to the code location of the argument pass at the call site for a ArgPass
// enclosing CallSiteParamAnnotationKey; Location is empty for a ArgPass enclosing ParamAnnotationKey.
Location string
Location string
AssignmentStr string
}

func (a ArgPassDeepPrestring) String() string {
Expand All @@ -917,6 +920,7 @@ func (a ArgPassDeepPrestring) String() string {
if a.Location != "" {
sb.WriteString(fmt.Sprintf(" at %s", a.Location))
}
sb.WriteString(a.AssignmentStr)
return sb.String()
}

Expand Down Expand Up @@ -1203,6 +1207,7 @@ func (u *UseAsReturnDeep) Prestring() Prestring {
key.RetNum,
u.IsNamedReturn,
key.FuncDecl.Type().(*types.Signature).Results().At(key.RetNum).Name(),
u.assignmentFlow.String(),
}
}

Expand All @@ -1212,14 +1217,18 @@ type UseAsReturnDeepPrestring struct {
RetNum int
IsNamedReturn bool
RetName string
AssignmentStr string
}

func (u UseAsReturnDeepPrestring) String() string {
var sb strings.Builder
via := ""
if u.IsNamedReturn {
via = fmt.Sprintf(" via named return `%s`", u.RetName)
}
return fmt.Sprintf("returned deeply from `%s()`%s in position %d", u.FuncName, via, u.RetNum)
sb.WriteString(fmt.Sprintf("returned deeply from `%s()`%s in position %d", u.FuncName, via, u.RetNum))
sb.WriteString(u.AssignmentStr)
return sb.String()
}

// overriding position value to point to the raw return statement, which is the source of the potential error
Expand Down
2 changes: 2 additions & 0 deletions annotation/consume_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var initStructsConsumingAnnotationTrigger = []any{
&FldEscape{TriggerIfNonNil: &TriggerIfNonNil{Ann: newMockKey()}},
&UseAsNonErrorRetDependentOnErrorRetNilability{TriggerIfNonNil: &TriggerIfNonNil{Ann: newMockKey()}},
&UseAsErrorRetWithNilabilityUnknown{TriggerIfNonNil: &TriggerIfNonNil{Ann: newMockKey()}},
&ArgPassDeep{TriggerIfDeepNonNil: &TriggerIfDeepNonNil{Ann: newMockKey()}},
&UseAsReturnDeep{TriggerIfDeepNonNil: &TriggerIfDeepNonNil{Ann: newMockKey()}},
}

// ConsumingAnnotationTriggerEqualsTestSuite tests for the `equals` method of all the structs that implement
Expand Down

0 comments on commit 8ee8677

Please sign in to comment.