@@ -95,19 +95,12 @@ class TypeVariableRefFinder : public ASTWalker {
9595 // If there is no type recorded yet, let's check whether
9696 // it is a placeholder variable implicitly generated by the
9797 // compiler.
98- if (var->getName ().hasDollarPrefix ()) {
99- if (auto *PB = var->getParentPatternBinding ()) {
100- auto patternTarget = CS.getSolutionApplicationTarget ({PB, 0 });
101- if (!patternTarget)
102- return {true , expr};
103-
104- auto patternType = patternTarget->getTypeOfUninitializedVar ();
105- if (patternType->hasPlaceholder ()) {
106- auto openedTy = CS.replaceInferableTypesWithTypeVars (
107- patternType, CS.getConstraintLocator (expr));
108- inferVariables (openedTy);
109- CS.setType (var, openedTy);
110- }
98+ if (auto *PB = var->getParentPatternBinding ()) {
99+ if (auto placeholderTy = isPlaceholderVar (PB)) {
100+ auto openedTy = CS.replaceInferableTypesWithTypeVars (
101+ placeholderTy, CS.getConstraintLocator (expr));
102+ inferVariables (openedTy);
103+ CS.setType (var, openedTy);
111104 }
112105 }
113106 }
@@ -553,13 +546,8 @@ class SyntacticElementConstraintGenerator
553546 // Keep track of this binding entry.
554547 cs.setSolutionApplicationTarget ({patternBinding, index}, *target);
555548
556- if (patternType->hasPlaceholder ()) {
557- if (auto *var = patternBinding->getSingleVar ()) {
558- if (var->getName ().hasDollarPrefix () &&
559- !patternBinding->isExplicitlyInitialized (index))
560- return ;
561- }
562- }
549+ if (isPlaceholderVar (patternBinding))
550+ return ;
563551
564552 if (cs.generateConstraints (*target, FreeTypeVariableBinding::Disallow)) {
565553 hadError = true ;
@@ -1829,6 +1817,11 @@ void ConjunctionElement::findReferencedVariables(
18291817
18301818 if (auto *patternBinding =
18311819 dyn_cast_or_null<PatternBindingDecl>(element.dyn_cast <Decl *>())) {
1820+ // Let's not walk into placeholder variable initializers, since they
1821+ // are type-checked separately right now.
1822+ if (isPlaceholderVar (patternBinding))
1823+ return ;
1824+
18321825 if (auto patternBindingElt =
18331826 locator
18341827 ->getLastElementAs <LocatorPathElt::PatternBindingElement>()) {
@@ -1842,3 +1835,21 @@ void ConjunctionElement::findReferencedVariables(
18421835 element.is <Expr *>() || element.isStmt (StmtKind::Return))
18431836 element.walk (refFinder);
18441837}
1838+
1839+ Type constraints::isPlaceholderVar (PatternBindingDecl *PB) {
1840+ auto *var = PB->getSingleVar ();
1841+ if (!var)
1842+ return Type ();
1843+
1844+ if (!var->getName ().hasDollarPrefix ())
1845+ return Type ();
1846+
1847+ auto *pattern = PB->getPattern (0 );
1848+ if (auto *typedPattern = dyn_cast<TypedPattern>(pattern)) {
1849+ auto type = typedPattern->getType ();
1850+ if (type && type->hasPlaceholder ())
1851+ return type;
1852+ }
1853+
1854+ return Type ();
1855+ }
0 commit comments