Skip to content

Commit 46f8dfa

Browse files
authored
Merge pull request #70106 from beccadax/a-little-too-implicit
[ClangImporter] Fix IUO ordering bug
2 parents 246e6d1 + b699f1c commit 46f8dfa

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,20 @@ IsImplicitlyUnwrappedOptionalRequest::evaluate(Evaluator &evaluator,
20562056
}
20572057

20582058
case DeclKind::Var:
2059+
if (decl->hasClangNode()) {
2060+
// ClangImporter does not use this request to compute whether imported
2061+
// declarations are IUOs; instead, it explicitly sets the bit itself when
2062+
// it imports the declaration's type. For most declarations this is done
2063+
// greedily, but for VarDecls, it is deferred until `getInterfaceType()`
2064+
// is called for the first time. (See apple/swift#61026.)
2065+
//
2066+
// Force the interface type, then see if a result for this request is now
2067+
// cached.
2068+
// FIXME: This is a little gross.
2069+
(void)decl->getInterfaceType();
2070+
if (auto cachedResult = this->getCachedResult())
2071+
return *cachedResult;
2072+
}
20592073
TyR = cast<VarDecl>(decl)->getTypeReprOrParentPatternTypeRepr();
20602074
break;
20612075

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void *ImportedIUOVar;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module ImportedIUO {
2+
header "imported_iuo.h"
3+
}

test/api-digester/imported_iuo.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
RUN: %empty-directory(%t)
2+
RUN: %api-digester -dump-sdk -module ImportedIUO -o %t/digest.json -module-cache-path %t/module-cache %clang-importer-sdk-nosource -I %S/Inputs/ImportedIUO -avoid-location
3+
RUN: %FileCheck --input-file %t/digest.json %s
4+
5+
CHECK: "name": "ImportedIUOVar",
6+
CHECK-NEXT: "printedName": "ImportedIUOVar",
7+
CHECK-NEXT: "children": [
8+
CHECK-NEXT: {
9+
CHECK-NEXT: "kind": "TypeNominal",
10+
CHECK-NEXT: "name": "ImplicitlyUnwrappedOptional",
11+
CHECK-NEXT: "printedName": "Swift.UnsafeMutableRawPointer!",

0 commit comments

Comments
 (0)