Skip to content

Commit a45928c

Browse files
authored
[Serialization] Handle XREFs to generic subscripts (#16554)
Found while compiling another project.
1 parent 19d8dd4 commit a45928c

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,8 +1687,11 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
16871687
}
16881688
} else if (auto alias = dyn_cast<TypeAliasDecl>(base)) {
16891689
paramList = alias->getGenericParams();
1690-
} else if (auto fn = dyn_cast<AbstractFunctionDecl>(base))
1690+
} else if (auto fn = dyn_cast<AbstractFunctionDecl>(base)) {
16911691
paramList = fn->getGenericParams();
1692+
} else if (auto subscript = dyn_cast<SubscriptDecl>(base)) {
1693+
paramList = subscript->getGenericParams();
1694+
}
16921695

16931696
if (!paramList) {
16941697
return llvm::make_error<XRefError>(

test/Serialization/Inputs/has_generic_subscript.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public struct GenericSubscript {
88
set { }
99
}
1010
}
11+
extension GenericSubscript: GenericSubscriptProto {}
1112

1213
public struct Outer<T> {
1314
public struct Inner<U> {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public protocol GenericSubscriptProto {
2+
subscript<K, V>(k: K) -> V { get set }
3+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/has_generic_subscript.swift
2+
// RUN: %target-build-swift -emit-module -o %t %S/Inputs/has_generic_subscript.swift %S/Inputs/has_generic_subscript_proto.swift -module-name has_generic_subscript
33
// RUN: llvm-bcanalyzer %t/has_generic_subscript.swiftmodule | %FileCheck %s
44
// RUN: %target-swift-frontend -emit-ir -I %t %s -o /dev/null
55

@@ -8,4 +8,5 @@
88
import has_generic_subscript
99

1010
var sillyDict = GenericSubscript()
11+
_ = sillyDict as GenericSubscriptProto
1112
var value: Int = sillyDict["beer"]

0 commit comments

Comments
 (0)