func (check *Checker) varDecl(obj *Var, lhs []*Var, typ, init syntax.Expr) {
assert(obj.typ == nil)
- // If we have undefined variable types due to errors,
- // mark variables as used to avoid follow-on errors.
- // Matches compiler behavior.
- defer func() {
- if obj.typ == Typ[Invalid] {
- obj.used = true
- }
- for _, lhs := range lhs {
- if lhs.typ == Typ[Invalid] {
- lhs.used = true
- }
- }
- }()
-
// determine type, if any
if typ != nil {
obj.typ = check.varType(typ)
func _() {
var ok = undef /* ERROR "undefined: undef" */
- x, ok := m[0] // must not crash
- _ = x
- // The next line is only needed for go/types, not types2.
- // TODO(gri) find cause and fix
- _ = ok
+ x, ok := m[0] // must not crash
+ _, _ = x, ok
}
func main() {
var c, d = 1, 2, 3 // ERROR "assignment mismatch: 2 variables but 3 values|wrong number of initializations|extra init expr"
var e, f, g = 1, 2 // ERROR "assignment mismatch: 3 variables but 2 values|wrong number of initializations|missing init expr"
- _, _, _, _ = c, d, e, f
+ _, _, _, _, _ = c, d, e, f, g
}
_ = 1, 2 // ERROR "assignment mismatch: 1 variable but 2 values|number of variables does not match|cannot assign"
c, d := 1 // ERROR "assignment mismatch: 2 variables but 1 value|wrong number of initializations|cannot initialize"
e, f := 1, 2, 3 // ERROR "assignment mismatch: 2 variables but 3 values|wrong number of initializations|cannot initialize"
- _, _, _, _ = c, d, e, f
+ _, _, _, _, _, _ = a, b, c, d, e, f
}
const (
a = 1 + iota // ERROR "invalid operation|incompatible types|cannot convert"
)
-
+ _, _ = n, y
}
const (