Skip to content

Commit 1a861df

Browse files
authored
[Serialization] Handle XREFs to generic subscripts (#16559)
Found while compiling another project.
1 parent d942e5d commit 1a861df

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
@@ -1659,8 +1659,11 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
16591659
}
16601660
} else if (auto alias = dyn_cast<TypeAliasDecl>(base)) {
16611661
paramList = alias->getGenericParams();
1662-
} else if (auto fn = dyn_cast<AbstractFunctionDecl>(base))
1662+
} else if (auto fn = dyn_cast<AbstractFunctionDecl>(base)) {
16631663
paramList = fn->getGenericParams();
1664+
} else if (auto subscript = dyn_cast<SubscriptDecl>(base)) {
1665+
paramList = subscript->getGenericParams();
1666+
}
16641667

16651668
if (!paramList) {
16661669
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)