Skip to content

Commit c34739c

Browse files
Merge pull request #30828 from aschwaighofer/irgen_fix_private_opaque_type_descriptor
Opaque type substitution also needs to take the access of a opaque ty…
2 parents 988c2ca + f887422 commit c34739c

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

lib/AST/Type.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,9 +2932,15 @@ substOpaqueTypesWithUnderlyingTypes(Type ty, const DeclContext *inContext,
29322932
static bool canSubstituteTypeInto(Type ty, const DeclContext *dc,
29332933
OpaqueSubstitutionKind kind,
29342934
bool isContextWholeModule) {
2935-
auto nominal = ty->getAnyNominal();
2936-
if (!nominal)
2935+
ValueDecl *nominal = ty->getAnyNominal();
2936+
if (!nominal) {
2937+
// We also need to check that the opaque type descriptor is accessible.
2938+
if (auto opaqueTy = ty->getAs<OpaqueTypeArchetypeType>())
2939+
nominal = opaqueTy->getDecl();
2940+
}
2941+
if (!nominal) {
29372942
return true;
2943+
}
29382944

29392945
switch (kind) {
29402946
case OpaqueSubstitutionKind::DontSubstitute:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Repo1
2+
3+
public extension MyThing {
4+
enum MyEnum {
5+
case mycase
6+
7+
private struct MyPrivateThing : Q {
8+
init() {
9+
}
10+
11+
var thing: some Q {
12+
return self
13+
}
14+
}
15+
16+
private var data: MyPrivateThing {
17+
switch self {
18+
case .mycase: return MyPrivateThing()
19+
}
20+
}
21+
22+
public var thing: some Q {
23+
self.data.thing
24+
}
25+
}
26+
}

test/IRGen/opaque_result_type_private_underlying.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// RUN: %empty-directory(%t)
66
// RUN: %target-swift-frontend -disable-availability-checking -enable-library-evolution -emit-module -emit-module-path=%t/Repo1.swiftmodule -module-name=Repo1 %S/Inputs/opaque_result_type_private_underlying_2.swift
77
// RUN: %target-swift-frontend -disable-availability-checking -I %t -emit-ir -primary-file %s -DUSEMODULE | %FileCheck %s --check-prefix=RESILIENT
8+
// RUN: %empty-directory(%t)
9+
// RUN: %target-swift-frontend -disable-availability-checking -enable-library-evolution -emit-module -emit-module-path=%t/Repo1.swiftmodule -module-name=Repo1 %S/Inputs/opaque_result_type_private_underlying_2.swift
10+
// RUN: %target-swift-frontend -disable-availability-checking -I %t -emit-ir -primary-file %s -primary-file %S/Inputs/opaque_result_type_private_underlying_3.swift -DUSEMODULE -DUSESECONDFILE | %FileCheck %s --check-prefix=RESILIENT
811

912
#if USEMODULE
1013
import Repo1
@@ -49,3 +52,19 @@ public struct UsePrivate: A {
4952
return PrivateUnderlying().bindAssoc()
5053
}
5154
}
55+
56+
#if USESECONDFILE
57+
public struct MyThing {
58+
public let which: MyEnum
59+
public init(_ which: MyEnum) {
60+
self.which = which
61+
}
62+
63+
public var body: some Q {
64+
self.thing
65+
}
66+
public var thing: some Q {
67+
self.which.thing
68+
}
69+
}
70+
#endif

0 commit comments

Comments
 (0)