mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Parse][SR-702] Disallow attributes before #if
This commit is contained in:
@@ -1896,6 +1896,19 @@ void Parser::delayParseFromBeginningToHere(ParserPosition BeginParserPosition,
|
||||
/// \endverbatim
|
||||
ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
|
||||
llvm::function_ref<void(Decl*)> Handler) {
|
||||
if (Tok.is(tok::pound_if)) {
|
||||
auto IfConfigResult = parseDeclIfConfig(Flags);
|
||||
if (auto ICD = IfConfigResult.getPtrOrNull()) {
|
||||
// The IfConfigDecl is ahead of its members in source order.
|
||||
Handler(ICD);
|
||||
// Copy the active members into the entries list.
|
||||
for (auto activeMember : ICD->getActiveMembers()) {
|
||||
Handler(activeMember);
|
||||
}
|
||||
}
|
||||
return IfConfigResult;
|
||||
}
|
||||
|
||||
Decl* LastDecl = nullptr;
|
||||
auto InternalHandler = [&](Decl *D) {
|
||||
LastDecl = D;
|
||||
@@ -2139,20 +2152,6 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
|
||||
DeclResult = parseDeclProtocol(Flags, Attributes);
|
||||
Status = DeclResult;
|
||||
break;
|
||||
case tok::pound_if: {
|
||||
auto IfConfigResult = parseDeclIfConfig(Flags);
|
||||
Status = IfConfigResult;
|
||||
|
||||
if (auto ICD = IfConfigResult.getPtrOrNull()) {
|
||||
// The IfConfigDecl is ahead of its members in source order.
|
||||
InternalHandler(ICD);
|
||||
// Copy the active members into the entries list.
|
||||
for (auto activeMember : ICD->getActiveMembers()) {
|
||||
InternalHandler(activeMember);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case tok::pound_sourceLocation:
|
||||
Status = parseLineDirective(false);
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
// RUN: %target-parse-verify-swift
|
||||
|
||||
public
|
||||
#if FOO // expected-error {{expected declaration}}
|
||||
var val1: Int = 0
|
||||
#else
|
||||
var val1: UInt = 1
|
||||
#endif
|
||||
|
||||
struct S2 { // expected-note {{in declaration of 'S2'}}
|
||||
@available(*, deprecated)
|
||||
#if FOO // expected-error {{expected declaration}}
|
||||
func fn1() {}
|
||||
#endif
|
||||
}
|
||||
|
||||
class C { // expected-note 3 {{in declaration of 'C'}}
|
||||
|
||||
#if os(iOS)
|
||||
|
||||
Reference in New Issue
Block a user