Skip to content

Commit f9143f7

Browse files
committed
Swift: fix extraction of empty files
1 parent 3a97517 commit f9143f7

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

swift/extractor/SwiftExtractor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ static void extractDeclarations(const SwiftExtractorConfiguration& config,
134134
for (auto decl : topLevelDecls) {
135135
visitor.extract(decl);
136136
}
137-
if (topLevelDecls.empty()) {
137+
// TODO the following will be moved to the dispatcher when we start caching swift file objects
138+
// for the moment, topLevelDecls always contains the current module, which does not have a file
139+
// associated with it, so we need a special case when there are no top level declarations
140+
if (topLevelDecls.size() == 1) {
138141
// In the case of empty files, the dispatcher is not called, but we still want to 'record' the
139142
// fact that the file was extracted
140143
llvm::SmallString<PATH_MAX> name(filename);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
| empty.swift:0:0:0:0 | empty.swift | getName: | empty.swift |
12
| file://:0:0:0:0 | | getName: | |
2-
| hello.swift:0:0:0:0 | hello.swift | getName: | hello.swift |
3+
| non_empty.swift:0:0:0:0 | non_empty.swift | getName: | non_empty.swift |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hello")

0 commit comments

Comments
 (0)