Skip to content

Commit 5216598

Browse files
authored
Merge pull request #71751 from xedin/rdar-123244479
[ClangImporter] Produce `ErrorType` for invalid variables
2 parents b719a6a + c533d42 commit 5216598

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,11 @@ class Verifier : public ASTWalker {
26542654
if (!var->hasInterfaceType())
26552655
return;
26562656

2657+
// The types for imported vars are produced lazily and
2658+
// could fail to import.
2659+
if (var->getClangDecl() && var->isInvalid())
2660+
return;
2661+
26572662
PrettyStackTraceDecl debugStack("verifying VarDecl", var);
26582663

26592664
// Variables must have materializable type.

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6510,7 +6510,7 @@ Type ClangImporter::importVarDeclType(
65106510
getImportTypeAttrs(decl));
65116511

65126512
if (!importedType)
6513-
return nullptr;
6513+
return ErrorType::get(Impl.SwiftContext);
65146514

65156515
if (importedType.isImplicitlyUnwrapped())
65166516
swiftDecl->setImplicitlyUnwrappedOptional(true);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t/src)
2+
// RUN: split-file %s %t/src
3+
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %t/src/main.swift \
5+
// RUN: -import-objc-header %t/src/Test.h \
6+
// RUN: -module-name main -I %t -verify
7+
8+
// REQUIRES: objc_interop
9+
10+
//--- Test.h
11+
@import Foundation;
12+
13+
extern const unsigned char TestDir[];
14+
15+
extern NSString * _Nonnull __TestDir __attribute__((swift_name("TestDir")));
16+
17+
//--- main.swift
18+
import Foundation
19+
20+
func test() {
21+
print(TestDir)
22+
}

0 commit comments

Comments
 (0)