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