aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/mod_vendor_goversion.txt
blob: aa4cb41171a5199aaf94fd8566d050798ec31fff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# https://golang.org/issue/36876: As of Go 1.17, vendor/modules.txt should
# indicate the language version used by each dependency.

[short] skip


# Control case: without a vendor directory, need117 builds and bad114 doesn't.

go build example.net/need117
! go build example.net/bad114
stderr '^bad114[/\\]bad114.go:15:2: duplicate method Y$'


# With a vendor/modules.txt lacking language versions, the world is topsy-turvy,
# because we have to guess a uniform version for everything.
#
# We always guess Go 1.16, because that was the last version for which
# 'go mod vendor' failed to record dependency versions, and it has most of
# the language features added since modules were introduced in Go 1.11.
#
# Even so, modules that declare 'go 1.17' and use 1.17 features spuriously fail
# to build, and modules that declare an older version and use features from a
# newer one spuriously build (instead of failing as they ought to).

go mod vendor

! grep 1.17 vendor/modules.txt
! go build example.net/need117
stderr '^vendor[/\\]example\.net[/\\]need117[/\\]need117.go:5:18: .*\n\tconversion of slices to array pointers only supported as of -lang=go1\.17'

! grep 1.13 vendor/modules.txt
go build example.net/bad114


# Upgrading the main module to 1.17 adds version annotations.
# Then everything is once again consistent with the non-vendored world.

go mod edit -go=1.17
go mod vendor

grep '^## explicit; go 1.17$' vendor/modules.txt
go build example.net/need117

grep '^## explicit; go 1.13$' vendor/modules.txt
! go build example.net/bad114
stderr '^vendor[/\\]example\.net[/\\]bad114[/\\]bad114.go:15:2: duplicate method Y$'

-- go.mod --
module example.net/m

go 1.16

require (
	example.net/bad114 v0.1.0
	example.net/need117 v0.1.0
)

replace (
	example.net/bad114 v0.1.0 => ./bad114
	example.net/need117 v0.1.0 => ./need117
)
-- m.go --
package m

import _ "example.net/bad114"
import _ "example.net/need117"

-- bad114/go.mod --
// Module bad114 requires Go 1.14 or higher, but declares Go 1.13.
module example.net/bad114

go 1.13
-- bad114/bad114.go --
package bad114

type XY interface {
	X()
	Y()
}

type YZ interface {
	Y()
	Z()
}

type XYZ interface {
	XY
	YZ
}

-- need117/go.mod --
// Module need117 requires Go 1.17 or higher.
module example.net/need117

go 1.17
-- need117/need117.go --
package need117

func init() {
		 s := make([]byte, 4)
		 _ = (*[4]byte)(s)
}