1 # The gotypesalias GODEBUG setting was introduced with Go 1.22 and removed
2 # with Go 1.27 but the GODEBUG behavior of the tool chain is independent of
3 # the module version; only the tool version matters (go.dev/issue/76163).
4 cp go.mod.20 go.mod
5
6 # Go 1.20 must accept the removed GODEBUG gotypesalias with default value
7 go build -n godebugok.go
8 ! stderr 'use of removed'
9
10 # This also applies to go vet
11 go vet godebugok.go
12 ! stderr .
13
14 # Go 1.20 must not accept the removed GODEBUG gotypesalias with old value
15 ! go build -n godebugold.go
16 stderr 'use of removed'
17
18 ! go vet godebugold.go
19 stderr 'use of removed'
20
21 # If the GODEBUG setting is valid in the .mod file the build succeeds.
22 cp go.mod.20.godebugok go.mod
23 go build -n main.go
24 ! stderr 'use of removed'
25
26 # In this case, setting an invalid value in the .go file leads to build failure.
27 ! go build -n godebugold.go
28 stderr 'use of removed'
29
30 # If the GODEBUG setting is invalid in the .mod file the build fails.
31 cp go.mod.20.godebugold go.mod
32 ! go build -n main.go
33 stderr 'use of removed'
34
35 # In this case, setting a valid value in the .go file does not remedy the failure.
36 ! go build -n godebugok.go
37 stderr 'use of removed'
38
39 [short] skip
40
41 # Using a removed GODEBUG with old value in the environment causes panic at startup.
42 cp go.mod.20 go.mod
43 env GODEBUG=gotypesalias=0
44 ! go run printgodebug.go
45 stderr 'removed GODEBUG gotypesalias set to old value'
46
47 # Using a removed GODEBUG with default value in the environment is ok.
48 env GODEBUG=gotypesalias=1
49 go run printgodebug.go
50 stdout gotypesalias=1
51
52 # Setting a removed GODEBUG with old value in the environment during runtime is not guarded against.
53 go run setgodebug.go
54 stdout gotypesalias=0
55
56 -- go.mod.20 --
57 go 1.20
58 module m
59
60 -- go.mod.20.godebugok --
61 go 1.20
62 module m
63 godebug gotypesalias=1
64
65 -- go.mod.20.godebugold --
66 go 1.20
67 module m
68 godebug gotypesalias=0
69
70 -- main.go --
71 package main
72 func main() {}
73
74 -- godebugok.go --
75 //go:debug gotypesalias=1
76
77 package main
78 func main() {}
79
80 -- godebugold.go --
81 //go:debug gotypesalias=0
82
83 package main
84 func main() {}
85
86 -- printgodebug.go --
87 package main
88
89 import "fmt"
90 import "os"
91
92 func main() {
93 fmt.Println(os.Getenv("GODEBUG"))
94 }
95
96 -- setgodebug.go --
97 package main
98
99 import "fmt"
100 import "os"
101
102 func main() {
103 os.Setenv("GODEBUG", "gotypesalias=0")
104 fmt.Println(os.Getenv("GODEBUG"))
105 }
106
View as plain text