case _Clear:
// clear(m)
- check.verifyVersionf(check.pkg, call.Fun, go1_21, "clear")
+ check.verifyVersionf(call.Fun, go1_21, "clear")
if !underIs(x.typ, func(u Type) bool {
switch u.(type) {
case _Max, _Min:
// max(x, ...)
// min(x, ...)
- check.verifyVersionf(check.pkg, call.Fun, go1_21, bin.name)
+ check.verifyVersionf(call.Fun, go1_21, bin.name)
op := token.LSS
if id == _Max {
case _Add:
// unsafe.Add(ptr unsafe.Pointer, len IntegerType) unsafe.Pointer
- check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Add")
+ check.verifyVersionf(call.Fun, go1_17, "unsafe.Add")
check.assignment(x, Typ[UnsafePointer], "argument to unsafe.Add")
if x.mode == invalid {
case _Slice:
// unsafe.Slice(ptr *T, len IntegerType) []T
- check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Slice")
+ check.verifyVersionf(call.Fun, go1_17, "unsafe.Slice")
ptr, _ := under(x.typ).(*Pointer) // TODO(gri) should this be coreType rather than under?
if ptr == nil {
case _SliceData:
// unsafe.SliceData(slice []T) *T
- check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.SliceData")
+ check.verifyVersionf(call.Fun, go1_20, "unsafe.SliceData")
slice, _ := under(x.typ).(*Slice) // TODO(gri) should this be coreType rather than under?
if slice == nil {
case _String:
// unsafe.String(ptr *byte, len IntegerType) string
- check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.String")
+ check.verifyVersionf(call.Fun, go1_20, "unsafe.String")
check.assignment(x, NewPointer(universeByte), "argument to unsafe.String")
if x.mode == invalid {
case _StringData:
// unsafe.StringData(str string) *byte
- check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.StringData")
+ check.verifyVersionf(call.Fun, go1_20, "unsafe.StringData")
check.assignment(x, Typ[String], "argument to unsafe.StringData")
if x.mode == invalid {
} else {
instErrPos = pos
}
- versionErr := !check.verifyVersionf(check.pkg, instErrPos, go1_18, "function instantiation")
+ versionErr := !check.verifyVersionf(instErrPos, go1_18, "function instantiation")
// targs and xlist are the type arguments and corresponding type expressions, or nil.
var targs []Type
// is an error checking its arguments (for example, if an incorrect number
// of arguments is supplied).
if got == want && want > 0 {
- check.verifyVersionf(check.pkg, inst, go1_18, "function instantiation")
+ check.verifyVersionf(inst, go1_18, "function instantiation")
sig = check.instantiateSignature(inst.Pos(), inst, sig, targs, xlist)
// targs have been consumed; proceed with checking arguments of the
// non-generic signature.
assert(len(tparams) == len(targs))
// at the moment we only support implicit instantiations of argument functions
- _ = len(genericArgs) > 0 && check.verifyVersionf(check.pkg, args[genericArgs[0]], go1_21, "implicitly instantiated function as argument")
+ _ = len(genericArgs) > 0 && check.verifyVersionf(args[genericArgs[0]], go1_21, "implicitly instantiated function as argument")
// tparams holds the type parameters of the callee and generic function arguments, if any:
// the first n type parameters belong to the callee, followed by mi type parameters for each
check.validType(t)
}
// If typ is local, an error was already reported where typ is specified/defined.
- _ = check.isImportedConstraint(rhs) && check.verifyVersionf(check.pkg, tdecl.Type, go1_18, "using type constraint %s", rhs)
+ _ = check.isImportedConstraint(rhs) && check.verifyVersionf(tdecl.Type, go1_18, "using type constraint %s", rhs)
}).describef(obj, "validType(%s)", obj.Name())
alias := tdecl.Alias
// alias declaration
if alias {
- check.verifyVersionf(check.pkg, tdecl, go1_9, "type aliases")
+ check.verifyVersionf(tdecl, go1_9, "type aliases")
check.brokenAlias(obj)
rhs = check.typ(tdecl.Type)
check.validAlias(obj, rhs)
// Check that RHS is otherwise at least of integer type.
switch {
case allInteger(y.typ):
- if !allUnsigned(y.typ) && !check.verifyVersionf(check.pkg, y, go1_13, invalidOp+"signed shift count %s", y) {
+ if !allUnsigned(y.typ) && !check.verifyVersionf(y, go1_13, invalidOp+"signed shift count %s", y) {
x.mode = invalid
return
}
// but there is no corresponding package object.
check.recordDef(file.PkgName, nil)
- fileScope := NewScope(check.pkg.scope, syntax.StartPos(file), syntax.EndPos(file), check.filename(fileNo))
+ fileScope := NewScope(pkg.scope, syntax.StartPos(file), syntax.EndPos(file), check.filename(fileNo))
fileScopes = append(fileScopes, fileScope)
check.recordScope(file, fileScope)
}
case *syntax.TypeDecl:
- _ = len(s.TParamList) != 0 && check.verifyVersionf(pkg, s.TParamList[0], go1_18, "type parameter")
+ _ = len(s.TParamList) != 0 && check.verifyVersionf(s.TParamList[0], go1_18, "type parameter")
obj := NewTypeName(s.Name.Pos(), pkg, s.Name.Value, nil)
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, tdecl: s})
}
check.recordDef(s.Name, obj)
}
- _ = len(s.TParamList) != 0 && !hasTParamError && check.verifyVersionf(pkg, s.TParamList[0], go1_18, "type parameter")
+ _ = len(s.TParamList) != 0 && !hasTParamError && check.verifyVersionf(s.TParamList[0], go1_18, "type parameter")
info := &declInfo{file: fileScope, fdecl: s}
// Methods are not package-level objects but we still track them in the
// object map so that we can handle them like regular functions (if the
assert(!isTypeParam(typ))
tset := computeInterfaceTypeSet(check, pos, u)
// If typ is local, an error was already reported where typ is specified/defined.
- if check != nil && check.isImportedConstraint(typ) && !check.verifyVersionf(check.pkg, pos, go1_18, "embedding constraint interface %s", typ) {
+ if check != nil && check.isImportedConstraint(typ) && !check.verifyVersionf(pos, go1_18, "embedding constraint interface %s", typ) {
continue
}
comparable = tset.comparable
}
terms = tset.terms
case *Union:
- if check != nil && !check.verifyVersionf(check.pkg, pos, go1_18, "embedding interface element %s", u) {
+ if check != nil && !check.verifyVersionf(pos, go1_18, "embedding interface element %s", u) {
continue
}
tset := computeUnionTypeSet(check, unionSets, pos, u)
if u == Typ[Invalid] {
continue
}
- if check != nil && !check.verifyVersionf(check.pkg, pos, go1_18, "embedding non-interface type %s", typ) {
+ if check != nil && !check.verifyVersionf(pos, go1_18, "embedding non-interface type %s", typ) {
continue
}
terms = termlist{{false, typ}}
}
return
case universeAny, universeComparable:
- if !check.verifyVersionf(check.pkg, e, go1_18, "predeclared %s", e.Value) {
+ if !check.verifyVersionf(e, go1_18, "predeclared %s", e.Value) {
return // avoid follow-on errors
}
}
}
case *syntax.IndexExpr:
- check.verifyVersionf(check.pkg, e, go1_18, "type instantiation")
+ check.verifyVersionf(e, go1_18, "type instantiation")
return check.instantiatedType(e.X, unpackExpr(e.Index), def)
case *syntax.ParenExpr:
}
// verifyVersionf is like allowVersion but also accepts a format string and arguments
-// which are used to report a version error if allowVersion returns false.
-func (check *Checker) verifyVersionf(pkg *Package, at poser, v version, format string, args ...interface{}) bool {
- if !check.allowVersion(pkg, at, v) {
+// which are used to report a version error if allowVersion returns false. It uses the
+// current package.
+func (check *Checker) verifyVersionf(at poser, v version, format string, args ...interface{}) bool {
+ if !check.allowVersion(check.pkg, at, v) {
check.versionErrorf(at, v, format, args...)
return false
}
case _Clear:
// clear(m)
- check.verifyVersionf(check.pkg, call.Fun, go1_21, "clear")
+ check.verifyVersionf(call.Fun, go1_21, "clear")
if !underIs(x.typ, func(u Type) bool {
switch u.(type) {
case _Max, _Min:
// max(x, ...)
// min(x, ...)
- check.verifyVersionf(check.pkg, call.Fun, go1_21, bin.name)
+ check.verifyVersionf(call.Fun, go1_21, bin.name)
op := token.LSS
if id == _Max {
case _Add:
// unsafe.Add(ptr unsafe.Pointer, len IntegerType) unsafe.Pointer
- check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Add")
+ check.verifyVersionf(call.Fun, go1_17, "unsafe.Add")
check.assignment(x, Typ[UnsafePointer], "argument to unsafe.Add")
if x.mode == invalid {
case _Slice:
// unsafe.Slice(ptr *T, len IntegerType) []T
- check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Slice")
+ check.verifyVersionf(call.Fun, go1_17, "unsafe.Slice")
ptr, _ := under(x.typ).(*Pointer) // TODO(gri) should this be coreType rather than under?
if ptr == nil {
case _SliceData:
// unsafe.SliceData(slice []T) *T
- check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.SliceData")
+ check.verifyVersionf(call.Fun, go1_20, "unsafe.SliceData")
slice, _ := under(x.typ).(*Slice) // TODO(gri) should this be coreType rather than under?
if slice == nil {
case _String:
// unsafe.String(ptr *byte, len IntegerType) string
- check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.String")
+ check.verifyVersionf(call.Fun, go1_20, "unsafe.String")
check.assignment(x, NewPointer(universeByte), "argument to unsafe.String")
if x.mode == invalid {
case _StringData:
// unsafe.StringData(str string) *byte
- check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.StringData")
+ check.verifyVersionf(call.Fun, go1_20, "unsafe.StringData")
check.assignment(x, Typ[String], "argument to unsafe.StringData")
if x.mode == invalid {
} else {
instErrPos = atPos(pos)
}
- versionErr := !check.verifyVersionf(check.pkg, instErrPos, go1_18, "function instantiation")
+ versionErr := !check.verifyVersionf(instErrPos, go1_18, "function instantiation")
// targs and xlist are the type arguments and corresponding type expressions, or nil.
var targs []Type
// is an error checking its arguments (for example, if an incorrect number
// of arguments is supplied).
if got == want && want > 0 {
- check.verifyVersionf(check.pkg, atPos(ix.Lbrack), go1_18, "function instantiation")
+ check.verifyVersionf(atPos(ix.Lbrack), go1_18, "function instantiation")
sig = check.instantiateSignature(ix.Pos(), ix.Orig, sig, targs, xlist)
// targs have been consumed; proceed with checking arguments of the
// non-generic signature.
assert(len(tparams) == len(targs))
// at the moment we only support implicit instantiations of argument functions
- _ = len(genericArgs) > 0 && check.verifyVersionf(check.pkg, args[genericArgs[0]], go1_21, "implicitly instantiated function as argument")
+ _ = len(genericArgs) > 0 && check.verifyVersionf(args[genericArgs[0]], go1_21, "implicitly instantiated function as argument")
// tparams holds the type parameters of the callee and generic function arguments, if any:
// the first n type parameters belong to the callee, followed by mi type parameters for each
check.validType(t)
}
// If typ is local, an error was already reported where typ is specified/defined.
- _ = check.isImportedConstraint(rhs) && check.verifyVersionf(check.pkg, tdecl.Type, go1_18, "using type constraint %s", rhs)
+ _ = check.isImportedConstraint(rhs) && check.verifyVersionf(tdecl.Type, go1_18, "using type constraint %s", rhs)
}).describef(obj, "validType(%s)", obj.Name())
alias := tdecl.Assign.IsValid()
// alias declaration
if alias {
- check.verifyVersionf(check.pkg, atPos(tdecl.Assign), go1_9, "type aliases")
+ check.verifyVersionf(atPos(tdecl.Assign), go1_9, "type aliases")
check.brokenAlias(obj)
rhs = check.typ(tdecl.Type)
check.validAlias(obj, rhs)
// Check that RHS is otherwise at least of integer type.
switch {
case allInteger(y.typ):
- if !allUnsigned(y.typ) && !check.verifyVersionf(check.pkg, y, go1_13, invalidOp+"signed shift count %s", y) {
+ if !allUnsigned(y.typ) && !check.verifyVersionf(y, go1_13, invalidOp+"signed shift count %s", y) {
x.mode = invalid
return
}
if f := check.fset.File(file.Pos()); f != nil {
pos, end = token.Pos(f.Base()), token.Pos(f.Base()+f.Size())
}
- fileScope := NewScope(check.pkg.scope, pos, end, check.filename(fileNo))
+ fileScope := NewScope(pkg.scope, pos, end, check.filename(fileNo))
fileScopes = append(fileScopes, fileScope)
check.recordScope(file, fileScope)
check.declarePkgObj(name, obj, di)
}
case typeDecl:
- _ = d.spec.TypeParams.NumFields() != 0 && check.verifyVersionf(pkg, d.spec.TypeParams.List[0], go1_18, "type parameter")
+ _ = d.spec.TypeParams.NumFields() != 0 && check.verifyVersionf(d.spec.TypeParams.List[0], go1_18, "type parameter")
obj := NewTypeName(d.spec.Name.Pos(), pkg, d.spec.Name.Name, nil)
check.declarePkgObj(d.spec.Name, obj, &declInfo{file: fileScope, tdecl: d.spec})
case funcDecl:
}
check.recordDef(d.decl.Name, obj)
}
- _ = d.decl.Type.TypeParams.NumFields() != 0 && !hasTParamError && check.verifyVersionf(pkg, d.decl.Type.TypeParams.List[0], go1_18, "type parameter")
+ _ = d.decl.Type.TypeParams.NumFields() != 0 && !hasTParamError && check.verifyVersionf(d.decl.Type.TypeParams.List[0], go1_18, "type parameter")
info := &declInfo{file: fileScope, fdecl: d.decl}
// Methods are not package-level objects but we still track them in the
// object map so that we can handle them like regular functions (if the
assert(!isTypeParam(typ))
tset := computeInterfaceTypeSet(check, pos, u)
// If typ is local, an error was already reported where typ is specified/defined.
- if check != nil && check.isImportedConstraint(typ) && !check.verifyVersionf(check.pkg, atPos(pos), go1_18, "embedding constraint interface %s", typ) {
+ if check != nil && check.isImportedConstraint(typ) && !check.verifyVersionf(atPos(pos), go1_18, "embedding constraint interface %s", typ) {
continue
}
comparable = tset.comparable
}
terms = tset.terms
case *Union:
- if check != nil && !check.verifyVersionf(check.pkg, atPos(pos), go1_18, "embedding interface element %s", u) {
+ if check != nil && !check.verifyVersionf(atPos(pos), go1_18, "embedding interface element %s", u) {
continue
}
tset := computeUnionTypeSet(check, unionSets, pos, u)
if u == Typ[Invalid] {
continue
}
- if check != nil && !check.verifyVersionf(check.pkg, atPos(pos), go1_18, "embedding non-interface type %s", typ) {
+ if check != nil && !check.verifyVersionf(atPos(pos), go1_18, "embedding non-interface type %s", typ) {
continue
}
terms = termlist{{false, typ}}
}
return
case universeAny, universeComparable:
- if !check.verifyVersionf(check.pkg, e, go1_18, "predeclared %s", e.Name) {
+ if !check.verifyVersionf(e, go1_18, "predeclared %s", e.Name) {
return // avoid follow-on errors
}
}
case *ast.IndexExpr, *ast.IndexListExpr:
ix := typeparams.UnpackIndexExpr(e)
- check.verifyVersionf(check.pkg, inNode(e, ix.Lbrack), go1_18, "type instantiation")
+ check.verifyVersionf(inNode(e, ix.Lbrack), go1_18, "type instantiation")
return check.instantiatedType(ix, def)
case *ast.ParenExpr:
}
// verifyVersionf is like allowVersion but also accepts a format string and arguments
-// which are used to report a version error if allowVersion returns false.
-func (check *Checker) verifyVersionf(pkg *Package, at positioner, v version, format string, args ...interface{}) bool {
- if !check.allowVersion(pkg, at, v) {
+// which are used to report a version error if allowVersion returns false. It uses the
+// current package.
+func (check *Checker) verifyVersionf(at positioner, v version, format string, args ...interface{}) bool {
+ if !check.allowVersion(check.pkg, at, v) {
check.versionErrorf(at, v, format, args...)
return false
}