mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CS] Walk UnresolvedDeclRefExprs in UnresolvedVarCollector
This matches what we do in VarRefCollector, and is needed because we currently delay the pre-checking of patterns due to the fact that we don't resolve them until CSGen. We ought to consider changing this, but until then, adjust the logic here to ensure we properly connect an ExprPattern that references an outer var with any type variables it may involve. rdar://112264204
This commit is contained in:
@@ -275,6 +275,27 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: We can see UnresolvedDeclRefExprs here because we don't walk into
|
||||
// patterns when running preCheckExpression, since we don't resolve patterns
|
||||
// until CSGen. We ought to consider moving pattern resolution into
|
||||
// pre-checking, which would allow us to pre-check patterns normally.
|
||||
if (auto *declRef = dyn_cast<UnresolvedDeclRefExpr>(expr)) {
|
||||
auto name = declRef->getName();
|
||||
auto loc = declRef->getLoc();
|
||||
if (name.isSimpleName() && loc.isValid()) {
|
||||
auto *varDecl =
|
||||
dyn_cast_or_null<VarDecl>(ASTScope::lookupSingleLocalDecl(
|
||||
CS.DC->getParentSourceFile(), name.getFullName(), loc));
|
||||
if (varDecl) {
|
||||
if (auto varType = CS.getTypeIfAvailable(varDecl)) {
|
||||
SmallPtrSet<TypeVariableType *, 4> typeVars;
|
||||
varType->getTypeVariables(typeVars);
|
||||
Vars.insert(typeVars.begin(), typeVars.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Action::Continue(expr);
|
||||
}
|
||||
|
||||
|
||||
15
test/Constraints/rdar112264204.swift
Normal file
15
test/Constraints/rdar112264204.swift
Normal file
@@ -0,0 +1,15 @@
|
||||
// RUN: %target-typecheck-verify-swift
|
||||
|
||||
// rdar://112264204: Make sure we can type-check this.
|
||||
func foo(_ fn: (Int) -> Void) {}
|
||||
|
||||
func bar(_ x: Int) {
|
||||
foo { [x] y in
|
||||
switch y {
|
||||
case x:
|
||||
()
|
||||
default:
|
||||
()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user