Skip to content

Commit ce69f1d

Browse files
committed
Decl attr applied to type check now more rigorous
Checks decl options to ensure it can be applied to a parameter & handles no escape special case as it's not a type attribute unless in SIL mode
1 parent 4023896 commit ce69f1d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/Parse/ParsePattern.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,24 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
259259
if (Tok.is(tok::colon)) {
260260
param.ColonLoc = consumeToken();
261261

262+
// Check if token is @ sign ergo an attribute
263+
if (Tok.is(tok::at_sign)) {
264+
Token nextToken = peekToken();
265+
// Check if attribute is invalid type attribute
266+
// and actually a declaration attribute
267+
TypeAttrKind TK = TypeAttributes::getAttrKindFromString(nextToken.getText());
268+
DeclAttrKind DK = DeclAttribute::getAttrKindFromString(nextToken.getText());
269+
if ((TK == TAK_Count || (TK == TAK_noescape && !isInSILMode()))
270+
&& DK != DAK_Count
271+
&& DeclAttribute::getOptions(declKind) & OnParam) {
272+
SourceLoc AtLoc = consumeToken(tok::at_sign);
273+
SourceLoc AttrLoc = consumeToken(tok::identifier);
274+
diagnose(AtLoc, diag::decl_attribute_applied_to_type)
275+
.fixItRemove(SourceRange(AtLoc, AttrLoc))
276+
.fixItInsert(StartLoc, "@" + nextToken.getText().str()+" ");
277+
}
278+
}
279+
262280
auto type = parseType(diag::expected_parameter_type);
263281
status |= type;
264282
param.Type = type.getPtrOrNull();

0 commit comments

Comments
 (0)