switch x.mode {
case invalid:
return // error reported before
- case constant_, variable, mapindex, value, nilvalue, commaok, commaerr:
+ case nilvalue:
+ assert(isTypes2)
+ // ok
+ case constant_, variable, mapindex, value, commaok, commaerr:
// ok
default:
// we may get here because of other problems (go.dev/issue/39634, crash 12)
// bool, rune, int, float64, complex128 or string respectively, depending
// on whether the value is a boolean, rune, integer, floating-point,
// complex, or string constant."
- if x.isNil() {
- if T == nil {
- check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
- x.mode = invalid
- return
+ if isTypes2 {
+ if x.isNil() {
+ if T == nil {
+ check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
+ x.mode = invalid
+ return
+ }
+ } else if T == nil || isNonTypeParamInterface(T) {
+ target = Default(x.typ)
+ }
+ } else { // go/types
+ if T == nil || isNonTypeParamInterface(T) {
+ if T == nil && x.typ == Typ[UntypedNil] {
+ check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
+ x.mode = invalid
+ return
+ }
+ target = Default(x.typ)
}
- } else if T == nil || isNonTypeParamInterface(T) {
- target = Default(x.typ)
}
newType, val, code := check.implicitTypeAndValue(x, target)
if code != 0 {
if x == nil {
var target *target
- // avoid calling syntax.String if not needed
+ // avoid calling ExprString if not needed
if T != nil {
if _, ok := under(T).(*Signature); ok {
target = newTarget(T, ExprString(lhs))
// orig_rhs[0] was already evaluated
}
-func (check *Checker) shortVarDecl(pos syntax.Pos, lhs, rhs []syntax.Expr) {
+func (check *Checker) shortVarDecl(pos poser, lhs, rhs []syntax.Expr) {
top := len(check.delayed)
scope := check.scope
ident, _ := lhs.(*syntax.Name)
if ident == nil {
check.useLHS(lhs)
+ // TODO(gri) This is redundant with a go/parser error. Consider omitting in go/types?
check.errorf(lhs, BadDecl, "non-name %s on left side of :=", lhs)
hasErr = true
continue
// a function begins at the end of the ConstSpec or VarSpec (ShortVarDecl
// for short variable declarations) and ends at the end of the innermost
// containing block."
- scopePos := syntax.EndPos(rhs[len(rhs)-1])
+ scopePos := endPos(rhs[len(rhs)-1])
for _, obj := range newVars {
check.declare(scope, nil, obj, scopePos) // id = nil: recordDef already called
}
variable // operand is an addressable variable
mapindex // operand is a map index expression (acts like a variable on lhs, commaok on rhs of an assignment)
value // operand is a computed value
- nilvalue // operand is the nil value
+ nilvalue // operand is the nil value - only used by types2
commaok // like value, but operand may be used in a comma,ok expression
commaerr // like commaok, but second value is error, not boolean
cgofunc // operand is a cgo function
variable: "variable",
mapindex: "map index expression",
value: "value",
- nilvalue: "nil",
+ nilvalue: "nil", // only used by types2
commaok: "comma, ok expression",
commaerr: "comma, error expression",
cgofunc: "cgo function",
}
// argErrPos returns the node (poser) for reportign an invalid argument count.
-func argErrPos(call *syntax.CallExpr) *syntax.CallExpr {
- return call
-}
+func argErrPos(call *syntax.CallExpr) *syntax.CallExpr { return call }
// ExprString returns a string representation of x.
func ExprString(x syntax.Node) string { return syntax.String(x) }
+
+// endPos returns the position of the first character immediately after node n.
+func endPos(n syntax.Node) syntax.Pos { return syntax.EndPos(n) }
+// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
+
// Copyright 2013 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.
switch x.mode {
case invalid:
return // error reported before
+ case nilvalue:
+ assert(isTypes2)
+ // ok
case constant_, variable, mapindex, value, commaok, commaerr:
// ok
default:
// bool, rune, int, float64, complex128 or string respectively, depending
// on whether the value is a boolean, rune, integer, floating-point,
// complex, or string constant."
- if T == nil || isNonTypeParamInterface(T) {
- if T == nil && x.typ == Typ[UntypedNil] {
- check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
- x.mode = invalid
- return
+ if isTypes2 {
+ if x.isNil() {
+ if T == nil {
+ check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
+ x.mode = invalid
+ return
+ }
+ } else if T == nil || isNonTypeParamInterface(T) {
+ target = Default(x.typ)
+ }
+ } else { // go/types
+ if T == nil || isNonTypeParamInterface(T) {
+ if T == nil && x.typ == Typ[UntypedNil] {
+ check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
+ x.mode = invalid
+ return
+ }
+ target = Default(x.typ)
}
- target = Default(x.typ)
}
newType, val, code := check.implicitTypeAndValue(x, target)
if code != 0 {
ident, _ := lhs.(*ast.Ident)
if ident == nil {
check.useLHS(lhs)
- // TODO(rFindley) this is redundant with a parser error. Consider omitting?
+ // TODO(gri) This is redundant with a go/parser error. Consider omitting in go/types?
check.errorf(lhs, BadDecl, "non-name %s on left side of :=", lhs)
hasErr = true
continue
// a function begins at the end of the ConstSpec or VarSpec (ShortVarDecl
// for short variable declarations) and ends at the end of the innermost
// containing block."
- scopePos := rhs[len(rhs)-1].End()
+ scopePos := endPos(rhs[len(rhs)-1])
for _, obj := range newVars {
check.declare(scope, nil, obj, scopePos) // id = nil: recordDef already called
}
type action func(in *ast.File)
var filemap = map[string]action{
- "alias.go": nil,
+ "alias.go": nil,
+ "assignments.go": func(f *ast.File) {
+ renameImportPath(f, `"cmd/compile/internal/syntax"->"go/ast"`)
+ renameSelectorExprs(f, "syntax.Name->ast.Ident", "ident.Value->ident.Name", "ast.Pos->token.Pos") // must happen before renaming identifiers
+ renameIdents(f, "syntax->ast", "poser->positioner", "nopos->noposn")
+ },
"array.go": nil,
"api_predicates.go": nil,
"basic.go": nil,
variable // operand is an addressable variable
mapindex // operand is a map index expression (acts like a variable on lhs, commaok on rhs of an assignment)
value // operand is a computed value
+ nilvalue // operand is the nil value - only used by types2
commaok // like value, but operand may be used in a comma,ok expression
commaerr // like commaok, but second value is error, not boolean
cgofunc // operand is a cgo function
variable: "variable",
mapindex: "map index expression",
value: "value",
+ nilvalue: "nil", // only used by types2
commaok: "comma, ok expression",
commaerr: "comma, error expression",
cgofunc: "cgo function",
func hasDots(call *ast.CallExpr) bool { return call.Ellipsis.IsValid() }
// dddErrPos returns the positioner for reporting an invalid ... use in a call.
-func dddErrPos(call *ast.CallExpr) positioner {
- return atPos(call.Ellipsis)
-}
+func dddErrPos(call *ast.CallExpr) positioner { return atPos(call.Ellipsis) }
// argErrPos returns positioner for reportign an invalid argument count.
-func argErrPos(call *ast.CallExpr) positioner {
- return inNode(call, call.Rparen)
-}
+func argErrPos(call *ast.CallExpr) positioner { return inNode(call, call.Rparen) }
+
+// endPos returns the position of the first character immediately after node n.
+func endPos(n ast.Node) token.Pos { return n.End() }