You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
slog.Info("msg", 1) // want `slog.Info arg "1" should be a string or a slog.Attr`
@@ -40,12 +48,24 @@ func F() {
40
48
r.Add("K", "v", "k") // want `call to slog.Record.Add missing a final value`
41
49
l.With("a", "b", 2) // want `slog.Logger.With arg "2" should be a string or a slog.Attr`
42
50
51
+
// Report the first problem if there are multiple bad keys.
52
+
slog.Debug("msg", "a", 1, 2, 3, 4) // want `slog.Debug arg "2" should be a string or a slog.Attr`
53
+
slog.Debug("msg", "a", 1, 2, 3, 4) // want `slog.Debug arg "2" should be a string or a slog.Attr`
54
+
43
55
slog.Log(nil, slog.LevelWarn, "msg", "a", "b", 2) // want `slog.Log arg "2" should be a string or a slog.Attr`
44
56
57
+
// Test method expression call.
58
+
(*slog.Logger).Debug(l, "msg", "a", 1, 2, 3) // want `slog.Logger.Debug arg "2" should be a string or a slog.Attr`
59
+
45
60
// Skip calls with spread args.
46
61
varargs []any
47
62
slog.Info("msg", args...)
48
63
64
+
// Report keys that are statically not exactly "string".
65
+
typeMyStringstring
66
+
myKey:=MyString("a") // any(x) looks like <MyString, "a">.
67
+
slog.Info("", myKey, 1) // want `slog.Info arg "myKey" should be a string or a slog.Attr`
68
+
49
69
// The variadic part of all the calls below begins with an argument of
50
70
// static type any, followed by an integer.
51
71
// Even though the we don't know the dynamic type of the first arg, and thus
@@ -74,4 +94,56 @@ func F() {
74
94
// Another invalid call we can't detect. Here the first argument is wrong.
75
95
a=1
76
96
slog.Info("msg", a, 7, "b", 5)
97
+
98
+
// We can detect the first case as the type of key is UntypedNil,
99
+
// e.g. not yet assigned to any and not yet an interface.
100
+
// We cannot detect the second.
101
+
slog.Debug("msg", nil, 2) // want `slog.Debug arg "nil" should be a string or a slog.Attr`
102
+
slog.Debug("msg", any(nil), 2)
103
+
104
+
// Recovery from unknown value.
105
+
slog.Debug("msg", any(nil), "a")
106
+
slog.Debug("msg", any(nil), "a", 2)
107
+
slog.Debug("msg", any(nil), "a", 2, "b") // want `call to slog.Debug has a missing or misplaced value`
108
+
slog.Debug("msg", any(nil), 2, 3, 4) // want "slog.Debug arg \\\"3\\\" should probably be a string or a slog.Attr \\(previous arg \\\"2\\\" cannot be a key\\)"
109
+
}
110
+
111
+
funcAll() {
112
+
// Test all functions and methods at least once.
113
+
var (
114
+
l*slog.Logger
115
+
r slog.Record
116
+
ctx context.Context
117
+
)
118
+
slog.Debug("msg", 1, 2) // want `slog.Debug arg "1" should be a string or a slog.Attr`
119
+
slog.Error("msg", 1, 2) // want `slog.Error arg "1" should be a string or a slog.Attr`
120
+
slog.Info("msg", 1, 2) // want `slog.Info arg "1" should be a string or a slog.Attr`
121
+
slog.Warn("msg", 1, 2) // want `slog.Warn arg "1" should be a string or a slog.Attr`
122
+
123
+
slog.DebugCtx(ctx, "msg", 1, 2) // want `slog.DebugCtx arg "1" should be a string or a slog.Attr`
124
+
slog.ErrorCtx(ctx, "msg", 1, 2) // want `slog.ErrorCtx arg "1" should be a string or a slog.Attr`
125
+
slog.InfoCtx(ctx, "msg", 1, 2) // want `slog.InfoCtx arg "1" should be a string or a slog.Attr`
126
+
slog.WarnCtx(ctx, "msg", 1, 2) // want `slog.WarnCtx arg "1" should be a string or a slog.Attr`
127
+
128
+
slog.Log(ctx, slog.LevelDebug, "msg", 1, 2) // want `slog.Log arg "1" should be a string or a slog.Attr`
129
+
130
+
l.Debug("msg", 1, 2) // want `slog.Logger.Debug arg "1" should be a string or a slog.Attr`
131
+
l.Error("msg", 1, 2) // want `slog.Logger.Error arg "1" should be a string or a slog.Attr`
132
+
l.Info("msg", 1, 2) // want `slog.Logger.Info arg "1" should be a string or a slog.Attr`
133
+
l.Warn("msg", 1, 2) // want `slog.Logger.Warn arg "1" should be a string or a slog.Attr`
134
+
135
+
l.DebugCtx(ctx, "msg", 1, 2) // want `slog.Logger.DebugCtx arg "1" should be a string or a slog.Attr`
136
+
l.ErrorCtx(ctx, "msg", 1, 2) // want `slog.Logger.ErrorCtx arg "1" should be a string or a slog.Attr`
137
+
l.InfoCtx(ctx, "msg", 1, 2) // want `slog.Logger.InfoCtx arg "1" should be a string or a slog.Attr`
138
+
l.WarnCtx(ctx, "msg", 1, 2) // want `slog.Logger.WarnCtx arg "1" should be a string or a slog.Attr`
139
+
140
+
l.Log(ctx, slog.LevelDebug, "msg", 1, 2) // want `slog.Logger.Log arg "1" should be a string or a slog.Attr`
141
+
142
+
_=l.With(1, 2) // want `slog.Logger.With arg "1" should be a string or a slog.Attr`
143
+
144
+
r.Add(1, 2) // want `slog.Record.Add arg "1" should be a string or a slog.Attr`
0 commit comments