Skip to content

Commit 828720c

Browse files
authored
Merge pull request swiftlang#32026 from xymus/spi-attr-range
[Parser] Fix source range of SPI attributes
2 parents 21f5032 + 6bead5c commit 828720c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,13 +1600,14 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
16001600
spiGroups.push_back(Context.getIdentifier(text));
16011601
consumeToken();
16021602

1603+
AttrRange = SourceRange(Loc, Tok.getLoc());
1604+
16031605
if (!consumeIf(tok::r_paren)) {
16041606
diagnose(Loc, diag::attr_expected_rparen, AttrName,
16051607
DeclAttribute::isDeclModifier(DK));
16061608
return false;
16071609
}
16081610

1609-
AttrRange = SourceRange(Loc, Tok.getLoc());
16101611
Attributes.add(SPIAccessControlAttr::create(Context, AtLoc, AttrRange,
16111612
spiGroups));
16121613
break;

test/SPI/local_spi_decls.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ public class BadPublicClass : SPIClass {} // expected-error {{class cannot be de
4747
@_spi(s) public func genFunc<T: PrivateProtocol>(_ t: T) {} // expected-error {{global function cannot be declared public because its generic parameter uses a private type}}
4848
public func genFuncBad<T: SPIProtocol>(_ t: T) {} // expected-error {{global function cannot be declared public because its generic parameter uses an '@_spi' type}}
4949
@_spi(S) public func genFuncSPI<T: SPIProtocol>(_ t: T) {} // OK
50+
51+
@_spi(S) private func privateCantBeSPI() {} // expected-error{{private global function cannot be declared '@_spi' because only public and open declarations can be '@_spi'}} {{1-10=}}
52+
@_spi(S) func internalCantBeSPI() {} // expected-error{{internal global function cannot be declared '@_spi' because only public and open declarations can be '@_spi'}} {{1-10=}}

0 commit comments

Comments
 (0)