Skip to content

Commit 5468f6c

Browse files
committed
fix: panic with range over iter.Seq
1 parent b645d32 commit 5468f6c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

contextcheck.go

+8
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,14 @@ func (r *runner) getFunction(instr ssa.Instruction) (f *ssa.Function) {
727727
}
728728

729729
func (r *runner) isCtxType(tp types.Type) bool {
730+
if p, ok := tp.(*types.Pointer); ok {
731+
// opaqueType is not exposed and lead to unreachable error.
732+
// Related to https://github.com/golang/tools/blob/63229bc79404d8cf2fe4e88ad569168fe251d993/go/ssa/builder.go#L107
733+
if p.Elem().String() == "deferStack" {
734+
return false
735+
}
736+
}
737+
730738
return types.Identical(tp, r.ctxTyp) || types.Identical(tp, r.ctxPTyp)
731739
}
732740

testdata/src/a/a.go

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package a // want package:"ctxCheck"
33
import (
44
"context"
55
"net/http"
6+
"slices"
67
)
78

89
type MyString string
@@ -171,3 +172,13 @@ func f17(ctx context.Context, k string) func() func() {
171172
}
172173
}
173174
}
175+
176+
/* ----------------- range over iter.Seq ----------------- */
177+
178+
func fIterSeq() {
179+
seq := slices.Values([]any{"a"})
180+
for range seq {
181+
_, cancel := context.WithCancel(context.Background())
182+
defer cancel()
183+
}
184+
}

0 commit comments

Comments
 (0)