Partially Revert #27862

When SE-110 was being implemented, we accidentally began to accept
closure parameter declarations that had no associated parameter names,
e.g.

foo { ([Int]) in /**/ }

This syntax has never been sanctioned by any version of Swift and should
be banned.  However, the change was made long enough ago and there are
enough clients relying on this, that we cannot accept the source break
at the moment.  For now, add a bit to ParamDecl that marks a parameter
as destructured, and back out setting the invalid bit on the type repr
for these kinds of declarations.

To prevent further spread of this syntax, stub in a warning that offers
to insert an anonymous parameter.

Resolves part of rdar://56673657 and improves QoI for errors like
rdar://56911630
This commit is contained in:
Robert Widmann
2019-11-08 17:29:16 -08:00
parent 1ea23d917f
commit dd1b15775d
9 changed files with 45 additions and 11 deletions

View File

@@ -5214,7 +5214,7 @@ enum class ParamSpecifier : uint8_t {
/// A function parameter declaration.
class ParamDecl : public VarDecl {
Identifier ArgumentName;
llvm::PointerIntPair<Identifier, 1, bool> ArgumentNameAndDestructured;
SourceLoc ParameterNameLoc;
SourceLoc ArgumentNameLoc;
SourceLoc SpecifierLoc;
@@ -5251,7 +5251,9 @@ public:
static ParamDecl *cloneWithoutType(const ASTContext &Ctx, ParamDecl *PD);
/// Retrieve the argument (API) name for this function parameter.
Identifier getArgumentName() const { return ArgumentName; }
Identifier getArgumentName() const {
return ArgumentNameAndDestructured.getPointer();
}
/// Retrieve the parameter (local) name for this function parameter.
Identifier getParameterName() const { return getName(); }
@@ -5270,6 +5272,9 @@ public:
TypeRepr *getTypeRepr() const { return TyRepr; }
void setTypeRepr(TypeRepr *repr) { TyRepr = repr; }
bool isDestructured() const { return ArgumentNameAndDestructured.getInt(); }
void setDestructured(bool repr) { ArgumentNameAndDestructured.setInt(repr); }
DefaultArgumentKind getDefaultArgumentKind() const {
return static_cast<DefaultArgumentKind>(Bits.ParamDecl.defaultArgumentKind);
}

View File

@@ -893,6 +893,8 @@ ERROR(parameter_operator_keyword_argument,none,
ERROR(parameter_unnamed,none,
"unnamed parameters must be written with the empty name '_'", ())
WARNING(parameter_unnamed_warn,none,
"unnamed parameters must be written with the empty name '_'", ())
ERROR(parameter_curry_syntax_removed,none,
"cannot have more than one parameter list", ())