[Parse] Set ErrorType to invalid ParamDecl

TypeChecker assumes invalid decl has valid type.

https://bugs.swift.org/browse/SR-8475
rdar://problem/43057057
This commit is contained in:
Rintaro Ishizaki
2018-08-09 15:11:55 +09:00
parent 88b75cd7bf
commit 5217b68f08
2 changed files with 18 additions and 3 deletions

View File

@@ -431,6 +431,14 @@ mapParsedParameters(Parser &parser,
paramNameLoc, paramName, Type(),
parser.CurDeclContext);
param->getAttrs() = paramInfo.Attrs;
auto setInvalid = [&]{
if (param->isInvalid())
return;
param->getTypeLoc().setInvalidType(ctx);
param->setInvalid();
};
bool parsingEnumElt
= (paramContext == Parser::ParameterContextKind::EnumElement);
// If we're not parsing an enum case, lack of a SourceLoc for both
@@ -440,7 +448,7 @@ mapParsedParameters(Parser &parser,
// If we diagnosed this parameter as a parse error, propagate to the decl.
if (paramInfo.isInvalid)
param->setInvalid();
setInvalid();
// If a type was provided, create the type for the parameter.
if (auto type = paramInfo.Type) {
@@ -464,8 +472,7 @@ mapParsedParameters(Parser &parser,
if (!param->isInvalid())
parser.diagnose(param->getLoc(), diag::missing_parameter_type);
param->getTypeLoc() = TypeLoc::withoutLoc(ErrorType::get(ctx));
param->setInvalid();
setInvalid();
} else if (paramInfo.SpecifierLoc.isValid()) {
StringRef specifier;
switch (paramInfo.SpecifierKind) {