diff --git a/go/types/assignments.go b/go/types/assignments.go index 743918e8..11cf1115 100644 --- a/go/types/assignments.go +++ b/go/types/assignments.go @@ -9,8 +9,6 @@ package types import ( "go/ast" "go/token" - - "code.google.com/p/go.tools/go/exact" ) // assignment reports whether x can be assigned to a variable of type T, @@ -94,7 +92,6 @@ func (check *Checker) initConst(lhs *Const, x *operand) { if x.mode != invalid { check.errorf(x.pos(), "cannot define constant %s (type %s) as %s", lhs.Name(), lhs.typ, x) } - lhs.val = exact.MakeUnknown() return } diff --git a/go/types/decl.go b/go/types/decl.go index 623d35f6..a71d8260 100644 --- a/go/types/decl.go +++ b/go/types/decl.go @@ -99,6 +99,9 @@ func (check *Checker) constDecl(obj *Const, typ, init ast.Expr) { check.iota = obj.val defer func() { check.iota = nil }() + // provide valid constant value under all circumstances + obj.val = exact.MakeUnknown() + // determine type, if any if typ != nil { t := check.typ(typ) diff --git a/go/types/testdata/constdecl.src b/go/types/testdata/constdecl.src index 0f71353b..8577cb92 100644 --- a/go/types/testdata/constdecl.src +++ b/go/types/testdata/constdecl.src @@ -82,4 +82,13 @@ func _() { ) } -// TODO(gri) move extra tests from testdata/const0.src into here \ No newline at end of file +// Test case for constant with invalid initialization. +// Caused panic because the constant value was not set up (gri - 7/8/2014). +func _() { + const ( + x string = missing /* ERROR "undeclared name" */ + y = x + "" + ) +} + +// TODO(gri) move extra tests from testdata/const0.src into here