...
1env GO111MODULE=on
2env GOTRACEBACK=single
3
4# Go 1.21 work module should leave panicnil with an implicit default.
5cp go.mod.21 go.mod
6go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
7! stdout panicnil
8stdout randautoseed=0
9
10# Go 1.21 work module should NOT set panicnil=1 in Go 1.20 dependency.
11cp go.mod.21 go.mod
12go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' q
13! stdout panicnil=1
14! stdout randautoseed
15
16go mod download rsc.io/panicnil # for go.sum
17go 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.
22cp go.mod.20 go.mod
23go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
24stdout panicnil=1
25stdout randautoseed=0
26
27# Go 1.20 work module should set panicnil=1 in Go 1.20 dependency.
28cp go.mod.20 go.mod
29go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}' q
30stdout panicnil=1
31! stdout randautoseed
32
33# Go 1.21 workspace should leave panicnil with an implicit default.
34cat q/go.mod
35cp go.work.21 go.work
36go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
37! stdout panicnil
38stdout randautoseed=0
39rm go.work
40
41# Go 1.20 workspace with Go 1.21 module cannot happen.
42cp go.work.20 go.work
43cp go.mod.21 go.mod
44! go list -f '{{.Module.GoVersion}} {{.DefaultGODEBUG}}'
45stderr 'go: module . listed in go.work file requires go >= 1.21'
46rm go.work
47
48[short] skip
49
50# Programs in Go 1.21 work module should trigger run-time error.
51cp go.mod.21 go.mod
52! go run .
53stderr 'panic: panic called with nil argument'
54
55! go run rsc.io/panicnil
56stderr 'panic: panic called with nil argument'
57
58# Programs in Go 1.20 work module use old panic nil behavior.
59cp go.mod.20 go.mod
60! go run .
61stderr 'panic: nil'
62
63! go run rsc.io/panicnil
64stderr 'panic: nil'
65
66# Programs in no module at all should use their go.mod file.
67rm go.mod
68! go run rsc.io/panicnil@v1.0.0
69stderr 'panic: nil'
70
71rm go.mod
72! go run rsc.io/panicnil@v1.1.0
73stderr 'panic: panic called with nil argument'
74
75-- go.work.21 --
76go 1.21
77use .
78use ./q
79
80-- go.work.20 --
81go 1.20
82use .
83use ./q
84
85-- go.mod.21 --
86go 1.21
87module m
88require q v1.0.0
89replace q => ./q
90require rsc.io/panicnil v1.0.0
91
92-- go.mod.20 --
93go 1.20
94module m
95require q v1.0.0
96replace q => ./q
97require rsc.io/panicnil v1.0.0
98
99-- p.go --
100//go:debug randautoseed=0
101
102package main
103
104func main() {
105 panic(nil)
106}
107
108-- q/go.mod --
109go 1.20
110module q
111
112-- q/q.go --
113package main
114func main() {}
View as plain text