Source file src/go/types/version.go

     1  // Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
     2  // Source: ../../cmd/compile/internal/types2/version.go
     3  
     4  // Copyright 2021 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  package types
     9  
    10  import (
    11  	"fmt"
    12  	"go/version"
    13  	"internal/goversion"
    14  )
    15  
    16  // A goVersion is a Go language version string of the form "go1.%d"
    17  // where d is the minor version number. goVersion strings don't
    18  // contain release numbers ("go1.20.1" is not a valid goVersion).
    19  type goVersion string
    20  
    21  // asGoVersion returns v as a goVersion (e.g., "go1.20.1" becomes "go1.20").
    22  // If v is not a valid Go version, the result is the empty string.
    23  func asGoVersion(v string) goVersion {
    24  	return goVersion(version.Lang(v))
    25  }
    26  
    27  // isValid reports whether v is a valid Go version.
    28  func (v goVersion) isValid() bool {
    29  	return v != ""
    30  }
    31  
    32  // cmp returns -1, 0, or +1 depending on whether x < y, x == y, or x > y,
    33  // interpreted as Go versions.
    34  func (x goVersion) cmp(y goVersion) int {
    35  	return version.Compare(string(x), string(y))
    36  }
    37  
    38  var (
    39  	// Go versions that introduced language changes
    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  	go1_28 = asGoVersion("go1.28")
    52  
    53  	// current (deployed) Go version
    54  	go_current = asGoVersion(fmt.Sprintf("go1.%d", goversion.Version))
    55  )
    56  
    57  // allowVersion reports whether the current effective Go version
    58  // (which may vary from one file to another) is allowed to use the
    59  // feature version (want).
    60  func (check *Checker) allowVersion(want goVersion) bool {
    61  	return !check.version.isValid() || check.version.cmp(want) >= 0
    62  }
    63  
    64  // verifyVersionf is like allowVersion but also accepts a format string and arguments
    65  // which are used to report a version error if allowVersion returns false.
    66  func (check *Checker) verifyVersionf(at positioner, v goVersion, format string, args ...any) bool {
    67  	if !check.allowVersion(v) {
    68  		check.versionErrorf(at, v, format, args...)
    69  		return false
    70  	}
    71  	return true
    72  }
    73  

View as plain text