1 env GO111MODULE=on
2 env GOTRACEBACK=single
3
4 # Go 1.21 work module should leave panicnil with an implicit default.
5 cp go.mod.21 go.mod
6 go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
7 ! stdout panicnil
8 stdout randautoseed=0
9
10 # Go 1.21 work module should NOT set panicnil=1 in Go 1.20 dependency.
11 cp go.mod.21 go.mod
12 go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' q
13 ! stdout panicnil=1
14 ! stdout randautoseed
15
16 go mod download rsc.io/panicnil # for go.sum
17 go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' rsc.io/panicnil
18 ! stdout panicnil=1
19 ! stdout randautoseed
20
21 # Go 1.20 work module should set panicnil=1.
22 cp go.mod.20 go.mod
23 go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
24 stdout panicnil=1
25 stdout randautoseed=0
26
27 # Go 1.20 work module should set panicnil=1 in Go 1.20 dependency.
28 cp go.mod.20 go.mod
29 go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' q
30 stdout panicnil=1
31 ! stdout randautoseed
32
33 # Go 1.21 workspace should leave panicnil with an implicit default.
34 cat q/go.mod
35 cp go.work.21 go.work
36 go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
37 ! stdout panicnil
38 stdout randautoseed=0
39 rm go.work
40
41 # Go 1.20 workspace with Go 1.21 module cannot happen.
42 cp go.work.20 go.work
43 cp go.mod.21 go.mod
44 ! go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
45 stderr 'go: module . listed in go.work file requires go >= 1.21'
46 rm go.work
47
48 # Go 1.21 go.mod with godebug default=go1.20
49 rm go.work
50 cp go.mod.21 go.mod
51 go mod edit -godebug default=go1.20 -godebug asynctimerchan=0
52 go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
53 stdout panicnil=1
54 stdout asynctimerchan=0
55
56 # Go 1.21 go.work with godebug default=go1.20
57 cp go.work.21 go.work
58 go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
59 ! stdout panicnil # go.work wins
60 stdout asynctimerchan=1 # go.work wins
61 go work edit -godebug default=go1.20 -godebug asynctimerchan=0
62 go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
63 stdout panicnil=1
64 stdout asynctimerchan=0
65 rm go.work
66
67 # Go 1.21 go.mod with //go:debug default=go1.20 in program
68 cp go.mod.21 go.mod
69 go list -tags godebug -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
70 stdout panicnil=1
71 stdout asynctimerchan=0
72
73 # Invalid //go:debug line should be diagnosed at build.
74 ! go build -tags godebugbad
75 stderr 'invalid //go:debug: value contains space'
76
77 [short] skip
78
79 # Programs in Go 1.21 work module should trigger run-time error.
80 cp go.mod.21 go.mod
81 ! go run .
82 stderr 'panic: panic called with nil argument'
83
84 ! go run rsc.io/panicnil
85 stderr 'panic: panic called with nil argument'
86
87 # Programs in Go 1.20 work module use old panic nil behavior.
88 cp go.mod.20 go.mod
89 ! go run .
90 stderr 'panic: nil'
91
92 ! go run rsc.io/panicnil
93 stderr 'panic: nil'
94
95 # Programs in no module at all should use their go.mod file.
96 rm go.mod
97 ! go run rsc.io/panicnil@v1.0.0
98 stderr 'panic: nil'
99
100 rm go.mod
101 ! go run rsc.io/panicnil@v1.1.0
102 stderr 'panic: panic called with nil argument'
103
104 -- go.work.21 --
105 go 1.21
106 use .
107 use ./q
108
109 -- go.work.20 --
110 go 1.20
111 use .
112 use ./q
113
114 -- go.mod.21 --
115 go 1.21
116 module m
117 require q v1.0.0
118 replace q => ./q
119 require rsc.io/panicnil v1.0.0
120
121 -- go.mod.20 --
122 go 1.20
123 module m
124 require q v1.0.0
125 replace q => ./q
126 require rsc.io/panicnil v1.0.0
127
128 -- p.go --
129 //go:debug randautoseed=0
130
131 package main
132
133 func main() {
134 panic(nil)
135 }
136
137 -- godebug.go --
138 //go:build godebug
139 //go:debug default=go1.20
140 //go:debug asynctimerchan=0
141
142 package main
143
144 -- godebugbad.go --
145 //go:build godebugbad
146 //go:debug default=go1.20 asynctimerchan=0
147
148 package main
149
150 -- q/go.mod --
151 go 1.20
152 module q
153
154 -- q/q.go --
155 package main
156 func main() {}
157
View as plain text