Skip to content

Commit ff7667e

Browse files
authored
[Sema] Validate Swift.Dictionary when resolving '[K: V]' sugar (swiftlang#18808)
Otherwise we'll try to use its generic signature before it's been computed.
1 parent 4f2ae17 commit ff7667e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,7 @@ Type TypeResolver::resolveDictionaryType(DictionaryTypeRepr *repr,
25332533
if (auto dictTy = TC.getDictionaryType(repr->getBrackets().Start, keyTy,
25342534
valueTy)) {
25352535
// Check the requirements on the generic arguments.
2536+
TC.validateDecl(dictDecl);
25362537
auto unboundTy = dictDecl->getDeclaredType()->castTo<UnboundGenericType>();
25372538

25382539
Type args[] = {keyTy, valueTy};

test/Sema/stdlib_sugar_types.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Test using type sugar before the types are defined.
2+
3+
// RUN: %target-swift-frontend -typecheck -parse-stdlib -module-name Swift -parse-as-library %s
4+
5+
struct Dummy {}
6+
7+
let a: Dummy? = .none
8+
let b: Dummy! = .none
9+
let c: [Dummy] = .init()
10+
let d: [Dummy: Dummy] = .init()
11+
12+
enum Optional<Wrapped> {
13+
case none
14+
case some(Wrapped)
15+
}
16+
17+
struct Array<Element> {}
18+
19+
struct Dictionary<Key, Value> {}

0 commit comments

Comments
 (0)