[ClangImporter] Produce ErrorType for invalid variables

If type couldn't be imported, produce error type instead
of `Type()` to align with other checks.

Resolves: rdar://123244479
This commit is contained in:
Pavel Yaskevich
2024-02-20 10:17:35 -08:00
committed by Pavel Yaskevich
parent 2ded8badf7
commit c533d4298e
3 changed files with 28 additions and 1 deletions

View File

@@ -2654,6 +2654,11 @@ public:
if (!var->hasInterfaceType())
return;
// The types for imported vars are produced lazily and
// could fail to import.
if (var->getClangDecl() && var->isInvalid())
return;
PrettyStackTraceDecl debugStack("verifying VarDecl", var);
// Variables must have materializable type.

View File

@@ -6510,7 +6510,7 @@ Type ClangImporter::importVarDeclType(
getImportTypeAttrs(decl));
if (!importedType)
return nullptr;
return ErrorType::get(Impl.SwiftContext);
if (importedType.isImplicitlyUnwrapped())
swiftDecl->setImplicitlyUnwrappedOptional(true);

View File

@@ -0,0 +1,22 @@
// RUN: %empty-directory(%t/src)
// RUN: split-file %s %t/src
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %t/src/main.swift \
// RUN: -import-objc-header %t/src/Test.h \
// RUN: -module-name main -I %t -verify
// REQUIRES: objc_interop
//--- Test.h
@import Foundation;
extern const unsigned char TestDir[];
extern NSString * _Nonnull __TestDir __attribute__((swift_name("TestDir")));
//--- main.swift
import Foundation
func test() {
print(TestDir)
}