@@ -95,19 +95,12 @@ class TypeVariableRefFinder : public ASTWalker {
95
95
// If there is no type recorded yet, let's check whether
96
96
// it is a placeholder variable implicitly generated by the
97
97
// 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);
111
104
}
112
105
}
113
106
}
@@ -553,13 +546,8 @@ class SyntacticElementConstraintGenerator
553
546
// Keep track of this binding entry.
554
547
cs.setSolutionApplicationTarget ({patternBinding, index}, *target);
555
548
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 ;
563
551
564
552
if (cs.generateConstraints (*target, FreeTypeVariableBinding::Disallow)) {
565
553
hadError = true ;
@@ -1829,6 +1817,11 @@ void ConjunctionElement::findReferencedVariables(
1829
1817
1830
1818
if (auto *patternBinding =
1831
1819
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
+
1832
1825
if (auto patternBindingElt =
1833
1826
locator
1834
1827
->getLastElementAs <LocatorPathElt::PatternBindingElement>()) {
@@ -1842,3 +1835,21 @@ void ConjunctionElement::findReferencedVariables(
1842
1835
element.is <Expr *>() || element.isStmt (StmtKind::Return))
1843
1836
element.walk (refFinder);
1844
1837
}
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