// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package types

import (
	
	
	
	
	
	
)

// langCompat reports an error if the representation of a numeric
// literal is not compatible with the current language version.
func ( *Checker) ( *ast.BasicLit) {
	 := .Value
	if len() <= 2 || .allowVersion(.pkg, 1, 13) {
		return
	}
	// len(s) > 2
	if strings.Contains(, "_") {
		.errorf(, _InvalidLit, "underscores in numeric literals requires go1.13 or later")
		return
	}
	if [0] != '0' {
		return
	}
	 := [1]
	if  == 'b' ||  == 'B' {
		.errorf(, _InvalidLit, "binary literals requires go1.13 or later")
		return
	}
	if  == 'o' ||  == 'O' {
		.errorf(, _InvalidLit, "0o/0O-style octal literals requires go1.13 or later")
		return
	}
	if .Kind != token.INT && ( == 'x' ||  == 'X') {
		.errorf(, _InvalidLit, "hexadecimal floating-point literals requires go1.13 or later")
	}
}

// allowVersion reports whether the given package
// is allowed to use version major.minor.
func ( *Checker) ( *Package, ,  int) bool {
	// We assume that imported packages have all been checked,
	// so we only have to check for the local package.
	if  != .pkg {
		return true
	}
	,  := .version.major, .version.minor
	return  == 0 &&  == 0 ||  >  ||  ==  &&  >= 
}

type version struct {
	major, minor int
}

// parseGoVersion parses a Go version string (such as "go1.12")
// and returns the version, or an error. If s is the empty
// string, the version is 0.0.
func parseGoVersion( string) ( version,  error) {
	if  == "" {
		return
	}
	 := goVersionRx.FindStringSubmatch()
	if  == nil {
		 = fmt.Errorf(`should be something like "go1.12"`)
		return
	}
	.major,  = strconv.Atoi([1])
	if  != nil {
		return
	}
	.minor,  = strconv.Atoi([2])
	return
}

// goVersionRx matches a Go version string, e.g. "go1.12".
var goVersionRx = regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)