-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile: don't apply -lang=go1.X restrictions to imported packages
Previously langSupported applied -lang as though it's a global restriction, but it's actually a per-package restriction. This CL fixes langSupported to take a *types.Pkg parameter to reflect this and updates its callers accordingly. This is relevant for signed shifts (added in Go 1.12), because they can be inlined into a Go 1.11 package; and for overlapping interfaces (added in Go 1.13), because they can be exported as part of the package's API. Today we require all Go packages to be compiled with the same toolchain, and all uses of langSupported are for controlling backwards-compatible features. So we can simply assume that since the imported packages type-checked successfully, they must have been compiled with an appropriate -lang setting. In the future if we ever want to use langSupported to control backwards-incompatible language changes, we might need to record the -lang flag used for compiling a package in its export data. Fixes #35437. Fixes #35442. Change-Id: Ifdf6a62ee80cd5fb4366cbf12933152506d1b36e Reviewed-on: https://go-review.googlesource.com/c/go/+/205977 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>
- Loading branch information
Showing
5 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Test that dependencies can use Go language features newer than the | ||
# Go version specified by the main module. | ||
|
||
env GO111MODULE=on | ||
|
||
go build | ||
|
||
-- go.mod -- | ||
module m | ||
go 1.12 | ||
require ( | ||
sub.1 v1.0.0 | ||
) | ||
replace ( | ||
sub.1 => ./sub | ||
) | ||
|
||
-- x.go -- | ||
package x | ||
|
||
import "sub.1" | ||
|
||
func F() { sub.F(0, 0) } | ||
|
||
var A sub.Alias | ||
var D sub.Defined | ||
|
||
-- sub/go.mod -- | ||
module m | ||
go 1.14 | ||
|
||
-- sub/sub.go -- | ||
package sub | ||
|
||
// signed shift counts added in Go 1.13 | ||
func F(l, r int) int { return l << r } | ||
|
||
type m1 interface { M() } | ||
type m2 interface { M() } | ||
|
||
// overlapping interfaces added in Go 1.14 | ||
type Alias = interface { m1; m2; M() } | ||
type Defined interface { m1; m2; M() } |