Skip to content

Commit 1094ae0

Browse files
committed
[ASTGen] Disable ExportedSourceFile for macro expanded buffers
1 parent 0030661 commit 1094ae0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,20 @@ void Parser::parseSourceFileViaASTGen(
330330
if (!needToParse)
331331
return;
332332

333+
switch (SF.Kind) {
334+
case SourceFileKind::Library:
335+
case SourceFileKind::Main:
336+
case SourceFileKind::Interface:
337+
break;
338+
case SourceFileKind::SIL:
339+
// FIXME: Support SIL.
340+
return;
341+
case SourceFileKind::MacroExpansion:
342+
case SourceFileKind::DefaultArgument:
343+
// FIXME: Support macro expanded sources.
344+
return;
345+
}
346+
333347
auto *exportedSourceFile = SF.getExportedSourceFile();
334348
if (!exportedSourceFile)
335349
return;

test/ASTGen/macros.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// REQUIRES: swift_swift_parser, asserts
2+
3+
// RUN: %empty-directory(%t)
4+
5+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/../Macros/Inputs/syntax_macro_definitions.swift
6+
7+
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -enable-experimental-feature ParserASTGen
8+
9+
@freestanding(declaration) macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition", type: "DefineAnonymousTypesMacro")
10+
@freestanding(expression) macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
11+
12+
func foo(a: Int) {
13+
_ = #stringify(a + 1)
14+
}
15+
16+
struct Outer {
17+
#anonymousTypes { "test" }
18+
}

0 commit comments

Comments
 (0)