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 <adonovan@google.com>
This commit is contained in:
Robert Griesemer 2015-01-07 13:15:59 -08:00
parent 8ab2c33bea
commit 4ad370efaa
2 changed files with 11 additions and 2 deletions

View File

@ -1126,9 +1126,12 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
} }
default: default:
// if utyp is invalid, an error was reported before
if utyp != Typ[Invalid] {
check.errorf(e.Pos(), "invalid composite literal type %s", typ) check.errorf(e.Pos(), "invalid composite literal type %s", typ)
goto Error goto Error
} }
}
x.mode = value x.mode = value
x.typ = typ x.typ = typ

View File

@ -35,3 +35,9 @@ func issue8799b(x int, ok bool) {
_ = !ok _ = !ok
_ = x _ = x
} }
func issue9182() {
type Point C /* ERROR undeclared */ .Point
// no error for composite literal based on unknown type
_ = Point{x: 1, y: 2}
}