blob: 5914e72093725fb1d245a4531831104f95cb6ff9 [file] [log] [blame]
// 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.
package vardecl
// Prerequisites.
func f() {}
func g() (x, y int) { return }
var m map[string]int
// Var decls must have a type or an initializer.
var _ int
var _, _ int
var _ /* ERROR "missing type or init expr" */
var _ /* ERROR "missing type or init expr" */, _
var _ /* ERROR "missing type or init expr" */, _, _
// The initializer must be an expression.
var _ = int /* ERROR "not an expression" */
var _ = f /* ERROR "used as value" */ ()
// Identifier and expression arity must match.
var _, _ = 1, 2
var _ = 1, 2 /* ERROR "extra init expr 2" */
var _, _ = 1 /* ERROR "assignment count mismatch" */
var _, _, _ /* ERROR "missing init expr for _" */ = 1, 2
var _ = g /* ERROR "2-valued expr" */ ()
var _, _ = g()
var _, _, _ = g /* ERROR "assignment count mismatch" */ ()
var _ = m["foo"]
var _, _ = m["foo"]
var _, _, _ = m /* ERROR "assignment count mismatch" */ ["foo"]
var _, _ int = 1, 2
var _ int = 1, 2 /* ERROR "extra init expr 2" */
var _, _ int = 1 /* ERROR "assignment count mismatch" */
var _, _, _ /* ERROR "missing init expr for _" */ int = 1, 2
var (
_, _ = 1, 2
_ = 1, 2 /* ERROR "extra init expr 2" */
_, _ = 1 /* ERROR "assignment count mismatch" */
_, _, _ /* ERROR "missing init expr for _" */ = 1, 2
_ = g /* ERROR "2-valued expr" */ ()
_, _ = g()
_, _, _ = g /* ERROR "assignment count mismatch" */ ()
_ = m["foo"]
_, _ = m["foo"]
_, _, _ = m /* ERROR "assignment count mismatch" */ ["foo"]
_, _ int = 1, 2
_ int = 1, 2 /* ERROR "extra init expr 2" */
_, _ int = 1 /* ERROR "assignment count mismatch" */
_, _, _ /* ERROR "missing init expr for _" */ int = 1, 2
)
// TODO(gri) consolidate other var decl checks in this file