Ignore invalid types as keys in context.WithValue
Signed-off-by: Joe Tsai <joetsai@google.com>
diff --git a/lint.go b/lint.go
index ccc5cff..6b6183f 100644
--- a/lint.go
+++ b/lint.go
@@ -1414,7 +1414,7 @@
}
key := f.pkg.typesInfo.Types[x.Args[1]]
- if _, ok := key.Type.(*types.Basic); ok {
+ if ktyp, ok := key.Type.(*types.Basic); ok && ktyp.Kind() != types.Invalid {
f.errorf(x, 1.0, category("context"), fmt.Sprintf("should not use basic type %s as key in context.WithValue", key.Type))
}
}
diff --git a/testdata/contextkeytypes.go b/testdata/contextkeytypes.go
index 6433e62..68dc36a 100644
--- a/testdata/contextkeytypes.go
+++ b/testdata/contextkeytypes.go
@@ -34,4 +34,5 @@
context.WithValue(c, complex128(1i), "bar") // MATCH /should not use basic type complex128 as key in context.WithValue/
context.WithValue(c, ctxKey{}, "bar") // ok
context.WithValue(c, &ctxKey{}, "bar") // ok
+ context.WithValue(c, invalid{}, "bar") // ok
}