Skip to content

Commit f8bf74b

Browse files
authored
Merge pull request #62773 from xedin/rdar-83418797
[CSClosure] Fix handling of non-representivate variables
2 parents 449acae + 4789369 commit f8bf74b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,22 @@ class TypeVariableRefFinder : public ASTWalker {
197197
return;
198198
}
199199

200+
// Don't walk into the opaque archetypes because they are not
201+
// transparent in this context - `some P` could reference a
202+
// type variables as substitutions which are visible only to
203+
// the outer context.
204+
if (type->is<OpaqueTypeArchetypeType>())
205+
return;
206+
200207
if (type->hasTypeVariable()) {
201208
SmallPtrSet<TypeVariableType *, 4> typeVars;
202209
type->getTypeVariables(typeVars);
203-
ReferencedVars.insert(typeVars.begin(), typeVars.end());
210+
211+
// Some of the type variables could be non-representative, so
212+
// we need to recurse into `inferTypeVariables` to property
213+
// handle them.
214+
for (auto *typeVar : typeVars)
215+
inferVariables(typeVar);
204216
}
205217
}
206218
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct Description: Hashable {
4+
let name: String
5+
let id: Int
6+
}
7+
8+
struct Value {
9+
let ID: Int?
10+
}
11+
12+
func test(allValues: [Value]) {
13+
// Type for `return nil` cannot be inferred at the moment because there is no join for result expressions.
14+
let owners = Set(allValues.compactMap { // expected-error {{generic parameter 'Element' could not be inferred}}
15+
// expected-note@-1 {{explicitly specify the generic arguments to fix this issue}}
16+
guard let id = $0.ID else { return nil }
17+
return Description(name: "", id: id)
18+
})
19+
}

0 commit comments

Comments
 (0)