From 4ad370efaa163bc6919068dba73f7f7344e03bc7 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 7 Jan 2015 13:15:59 -0800 Subject: [PATCH] go/types: avoid follow-up error if composite literal type is unknown Fixes #9182. Change-Id: I7090e600e9981131db7f323e7ce6419017e95458 Reviewed-on: https://go-review.googlesource.com/2481 Reviewed-by: Alan Donovan --- go/types/expr.go | 7 +++++-- go/types/testdata/issues.src | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/go/types/expr.go b/go/types/expr.go index c55ce6a1..71b1b34e 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -1126,8 +1126,11 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { } default: - check.errorf(e.Pos(), "invalid composite literal type %s", typ) - goto Error + // if utyp is invalid, an error was reported before + if utyp != Typ[Invalid] { + check.errorf(e.Pos(), "invalid composite literal type %s", typ) + goto Error + } } x.mode = value diff --git a/go/types/testdata/issues.src b/go/types/testdata/issues.src index 58c450f8..417f06c5 100644 --- a/go/types/testdata/issues.src +++ b/go/types/testdata/issues.src @@ -35,3 +35,9 @@ func issue8799b(x int, ok bool) { _ = !ok _ = x } + +func issue9182() { + type Point C /* ERROR undeclared */ .Point + // no error for composite literal based on unknown type + _ = Point{x: 1, y: 2} +}