Skip to content

Commit

Permalink
Merge pull request #673 from SquaredTiki/sr215-fix
Browse files Browse the repository at this point in the history
[Parser] Fix-it for declaration attributes being applied to parameter types (SR-215)
  • Loading branch information
gribozavr committed Jan 13, 2016
2 parents 7026909 + 9ced244 commit 72fdaff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/Parse/ParsePattern.cpp
Expand Up @@ -235,6 +235,21 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
if (Tok.is(tok::colon)) {
param.ColonLoc = consumeToken();

// Check if token is @ sign ergo an attribute
if (Tok.is(tok::at_sign)) {
Token nextToken = peekToken();
// Check if attribute is invalid type attribute
// and actually a declaration attribute
if (TypeAttributes::getAttrKindFromString(nextToken.getText()) == TAK_Count
&& DeclAttribute::getAttrKindFromString(nextToken.getText()) != DAK_Count) {
SourceLoc AtLoc = consumeToken(tok::at_sign);
SourceLoc AttrLoc = consumeToken(tok::identifier);
diagnose(AtLoc, diag::decl_attribute_applied_to_type)
.fixItRemove(SourceRange(AtLoc, AttrLoc))
.fixItInsert(StartLoc, "@" + nextToken.getText().str()+" ");
}
}

auto type = parseType(diag::expected_parameter_type);
status |= type;
param.Type = type.getPtrOrNull();
Expand Down
2 changes: 2 additions & 0 deletions test/attr/attr_noescape.swift
Expand Up @@ -2,6 +2,8 @@

@noescape var fn : () -> Int = { 4 } // expected-error {{@noescape may only be used on 'parameter' declarations}} {{1-11=}}

func appliedToType(g: @noescape ()->Void) { g() } // expected-error {{attribute can only be applied to declarations, not types}} {{20-20=@noescape }} {{23-33=}}

func doesEscape(fn : () -> Int) {}

func takesGenericClosure<T>(a : Int, @noescape _ fn : () -> T) {}
Expand Down

0 comments on commit 72fdaff

Please sign in to comment.