mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
committed by
Pavel Yaskevich
parent
2ded8badf7
commit
c533d4298e
@@ -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.
|
||||
|
||||
@@ -6510,7 +6510,7 @@ Type ClangImporter::importVarDeclType(
|
||||
getImportTypeAttrs(decl));
|
||||
|
||||
if (!importedType)
|
||||
return nullptr;
|
||||
return ErrorType::get(Impl.SwiftContext);
|
||||
|
||||
if (importedType.isImplicitlyUnwrapped())
|
||||
swiftDecl->setImplicitlyUnwrappedOptional(true);
|
||||
|
||||
22
test/ClangImporter/invalid_vars_should_have_error_type.swift
Normal file
22
test/ClangImporter/invalid_vars_should_have_error_type.swift
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user