Lock down on the use of default values in patterns and types.

Per previous discussions, we only want to allow default values for
uncurried 'func' and 'constructor' parameters, and not for return
types or arbitrary tuple types. Introduce this restriction, fixing
part of <rdar://problem/13372694>. 



Swift SVN r6156
This commit is contained in:
Doug Gregor
2013-07-11 17:53:05 +00:00
parent 4078785192
commit 50d6fd0455
6 changed files with 55 additions and 80 deletions

View File

@@ -435,38 +435,6 @@ bool Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
return Invalid;
}
/// value-specifier:
/// ':' type-annotation
/// ':' type-annotation '=' expr
/// '=' expr
bool Parser::parseValueSpecifier(TypeLoc &Ty,
NullablePtr<Expr> &Init) {
// Diagnose when we don't have a type or an expression.
if (Tok.isNot(tok::colon) && Tok.isNot(tok::equal)) {
diagnose(Tok, diag::expected_type_or_init);
// TODO: Recover better by still creating var, but making it have
// 'invalid' type so that uses of the identifier are not errors.
return true;
}
// Parse the type if present.
if (consumeIf(tok::colon) &&
parseTypeAnnotation(Ty, diag::expected_type))
return true;
// Parse the initializer, if present.
if (consumeIf(tok::equal)) {
NullablePtr<Expr> Tmp = parseExpr(diag::expected_initializer_expr);
if (Tmp.isNull())
return true;
Init = Tmp.get();
}
return false;
}
/// diagnoseRedefinition - Diagnose a redefinition error, with a note
/// referring back to the original definition.