Skip to content

Commit a8e2fba

Browse files
committed
[CS] Always eagerly bind member type var to hole for missing member
We know this is where the issue is so we ought to always produce a concrete hole.
1 parent 2a0172d commit a8e2fba

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

lib/Sema/CSFix.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,11 @@ DefineMemberBasedOnUse::diagnoseForAmbiguity(CommonFixesArray commonFixes) const
939939
const auto *solution = solutionAndFix.first;
940940
const auto *fix = solutionAndFix.second->getAs<DefineMemberBasedOnUse>();
941941

942-
auto baseType = solution->simplifyType(fix->BaseType);
942+
// Ignore differences in optionality since we can look through an optional
943+
// to resolve an implicit member `.foo`.
944+
auto baseType = solution->simplifyType(fix->BaseType)
945+
->getMetatypeInstanceType()
946+
->lookThroughAllOptionalTypes();
943947
if (!concreteBaseType)
944948
concreteBaseType = baseType;
945949

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11604,22 +11604,11 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
1160411604
// `key path` constraint can't be retired until all components
1160511605
// are simplified.
1160611606
addTypeVariableConstraintsToWorkList(memberTypeVar);
11607-
} else if (isa<Expr *>(locator->getAnchor()) &&
11608-
!getSemanticsProvidingParentExpr(
11609-
getAsExpr(locator->getAnchor()))) {
11610-
// If there are no contextual expressions that could provide
11611-
// a type for the member type variable, let's default it to
11612-
// a placeholder eagerly so it could be propagated to the
11613-
// pattern if necessary.
11614-
recordTypeVariablesAsHoles(memberTypeVar);
11615-
} else if (locator->isLastElement<LocatorPathElt::PatternMatch>()) {
11616-
// Let's handle member patterns specifically because they use
11617-
// equality instead of argument application constraint, so allowing
11618-
// them to bind member could mean missing valid hole positions in
11619-
// the pattern.
11620-
recordTypeVariablesAsHoles(memberTypeVar);
1162111607
} else {
11622-
recordPotentialHole(memberTypeVar);
11608+
// Eagerly turn the member type variable into a hole since we know
11609+
// this is where the issue is and we've recorded a fix for it. This
11610+
// avoids producing unnecessary holes for e.g generic parameters.
11611+
recordTypeVariablesAsHoles(memberTypeVar);
1162311612
}
1162411613
}
1162511614

test/Constraints/closures.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ do {
13621362
}
13631363
}
13641364

1365-
test { // expected-error {{invalid conversion from throwing function of type '(Int) throws -> Void' to non-throwing function type '(Int) -> Void'}}
1365+
test { // expected-error {{invalid conversion from throwing function of type '(Int) throws -> _' to non-throwing function type '(Int) -> Void'}}
13661366
try $0.missing // expected-error {{value of type 'Int' has no member 'missing'}}
13671367
}
13681368
}

test/type/protocol_composition.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,9 @@ takesP1AndP2([DoesNotExist & P1 & P2]()) // expected-error {{cannot find 'DoesNo
196196
// expected-error@-2 {{binary operator '&' cannot be applied to operands of type 'UInt8' and '(any P1).Type'}}
197197
// expected-note@-3 2 {{overloads for '&' exist with these partially matching parameter lists}}
198198
// expected-error@-4 {{cannot call value of non-function type '[UInt8]'}}
199-
takesP1AndP2([Swift.DoesNotExist & P1 & P2]()) // expected-error {{module 'Swift' has no member named 'DoesNotExist'}}
200-
// expected-error@-1 {{binary operator '&' cannot be applied to operands of type 'UInt8' and '(any P2).Type'}}
201-
// expected-error@-2 {{binary operator '&' cannot be applied to operands of type 'UInt8' and '(any P1).Type'}}
202-
// expected-note@-3 2 {{overloads for '&' exist with these partially matching parameter lists}}
203-
// expected-error@-4 {{cannot call value of non-function type '[UInt8]'}}
199+
takesP1AndP2([Swift.DoesNotExist & P1 & P2]())
200+
// expected-error@-1 {{module 'Swift' has no member named 'DoesNotExist'}}
201+
// expected-error@-2 {{cannot call value of non-function type '[Element]'}}
204202

205203
typealias T08 = P1 & inout P2 // expected-error {{'inout' may only be used on parameters}}
206204
typealias T09 = P1 & __shared P2 // expected-error {{'__shared' may only be used on parameters}}

0 commit comments

Comments
 (0)