Text file src/cmd/go/testdata/script/mod_vendor_goversion.txt

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

View as plain text