Source file
src/go/types/version.go
1
2
3
4
5
6
7
8 package types
9
10 import (
11 "fmt"
12 "go/version"
13 "internal/goversion"
14 )
15
16
17
18
19 type goVersion string
20
21
22
23 func asGoVersion(v string) goVersion {
24 return goVersion(version.Lang(v))
25 }
26
27
28 func (v goVersion) isValid() bool {
29 return v != ""
30 }
31
32
33
34 func (x goVersion) cmp(y goVersion) int {
35 return version.Compare(string(x), string(y))
36 }
37
38 var (
39
40 go1_9 = asGoVersion("go1.9")
41 go1_13 = asGoVersion("go1.13")
42 go1_14 = asGoVersion("go1.14")
43 go1_17 = asGoVersion("go1.17")
44 go1_18 = asGoVersion("go1.18")
45 go1_20 = asGoVersion("go1.20")
46 go1_21 = asGoVersion("go1.21")
47 go1_22 = asGoVersion("go1.22")
48 go1_23 = asGoVersion("go1.23")
49 go1_26 = asGoVersion("go1.26")
50 go1_27 = asGoVersion("go1.27")
51
52
53 go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
54 )
55
56
57
58
59 func (check *Checker) allowVersion(want goVersion) bool {
60 return !check.version.isValid() || check.version.cmp(want) >= 0
61 }
62
63
64
65 func (check *Checker) verifyVersionf(at positioner, v goVersion, format string, args ...any) bool {
66 if !check.allowVersion(v) {
67 check.versionErrorf(at, v, format, args...)
68 return false
69 }
70 return true
71 }
72
View as plain text