1 # https://golang.org/issue/36876: As of Go 1.17, vendor/modules.txt should
2 # indicate the language version used by each dependency.
3
4 [short] skip
5
6 # Control case: without a vendor directory, need117 builds and bad114 doesn't.
7
8 go build example.net/need117
9 ! go build example.net/bad114
10 stderr '^bad114[/\\]bad114.go:15:2: duplicate method .?Y.?( .*)?$'
11
12
13 # With a vendor/modules.txt lacking language versions, the world is topsy-turvy,
14 # because we have to guess a uniform version for everything.
15 #
16 # We always guess Go 1.16, because that was the last version for which
17 # 'go mod vendor' failed to record dependency versions, and it has most of
18 # the language features added since modules were introduced in Go 1.11.
19 #
20 # Even so, modules that declare 'go 1.17' and use 1.17 features spuriously fail
21 # to build, and modules that declare an older version and use features from a
22 # newer one spuriously build (instead of failing as they ought to).
23
24 go mod vendor
25
26 ! grep 1.17 vendor/modules.txt
27 ! go build example.net/need117
28 stderr '^vendor[/\\]example\.net[/\\]need117[/\\]need117.go:5:1[89]:'
29 stderr 'conversion of slice to array pointer requires go1\.17 or later'
30
31 ! grep 1.13 vendor/modules.txt
32 go build example.net/bad114
33
34
35 # Upgrading the main module to 1.17 adds version annotations.
36 # Then everything is once again consistent with the non-vendored world.
37
38 go mod edit -go=1.17
39 go mod vendor
40
41 grep '^## explicit; go 1.17$' vendor/modules.txt
42 go build example.net/need117
43
44 grep '^## explicit; go 1.13$' vendor/modules.txt
45 ! go build example.net/bad114
46 stderr '^vendor[/\\]example\.net[/\\]bad114[/\\]bad114.go:15:2: duplicate method .?Y.?( .*)?$'
47
48 -- go.mod --
49 module example.net/m
50
51 go 1.16
52
53 require (
54 example.net/bad114 v0.1.0
55 example.net/need117 v0.1.0
56 )
57
58 replace (
59 example.net/bad114 v0.1.0 => ./bad114
60 example.net/need117 v0.1.0 => ./need117
61 )
62 -- m.go --
63 package m
64
65 import _ "example.net/bad114"
66 import _ "example.net/need117"
67
68 -- bad114/go.mod --
69 // Module bad114 requires Go 1.14 or higher, but declares Go 1.13.
70 module example.net/bad114
71
72 go 1.13
73 -- bad114/bad114.go --
74 package bad114
75
76 type XY interface {
77 X()
78 Y()
79 }
80
81 type YZ interface {
82 Y()
83 Z()
84 }
85
86 type XYZ interface {
87 XY
88 YZ
89 }
90
91 -- need117/go.mod --
92 // Module need117 requires Go 1.17 or higher.
93 module example.net/need117
94
95 go 1.17
96 -- need117/need117.go --
97 package need117
98
99 func init() {
100 s := make([]byte, 4)
101 _ = (*[4]byte)(s)
102 }
103
View as plain text