Skip to content

Commit 3cc6ce5

Browse files
committed
feat: improve position for closure
1 parent 7fdfd4d commit 3cc6ce5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

contextcheck.go

+16
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,22 @@ func (r *runner) checkFuncWithCtx(f *ssa.Function, tp entryType) {
589589

590590
func (r *runner) Reportf(instr ssa.Instruction, format string, args ...interface{}) {
591591
pos := instr.Pos()
592+
593+
if !pos.IsValid() && instr.Block() != nil {
594+
if closure, ok := instr.(*ssa.MakeClosure); ok {
595+
for _, in := range closure.Block().Instrs {
596+
if !in.Pos().IsValid() {
597+
continue
598+
}
599+
600+
if r, ok := in.(*ssa.Return); ok {
601+
pos = r.Pos()
602+
break
603+
}
604+
}
605+
}
606+
}
607+
592608
if !pos.IsValid() && instr.Parent() != nil {
593609
pos = instr.Parent().Pos()
594610
}

testdata/src/a/a.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ func f13[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 |
158158

159159
/* ----------------- issue 21 ----------------- */
160160

161-
func f16(ctx context.Context, k string) func() { // want "Function `f16\\$1` should pass the context parameter"
162-
return func() {
161+
func f16(ctx context.Context, k string) func() {
162+
return func() { // want "Function `f16\\$1` should pass the context parameter"
163163
f16(context.Background(), k)
164164
}
165165
}

0 commit comments

Comments
 (0)