Skip to content

Commit dc10f60

Browse files
committed
[ConstraintSystem] Don't attempt missing function call diagnostics if
there is no function expression explicitly written in the source code.
1 parent 3064594 commit dc10f60

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,12 @@ void ContextualFailure::tryFixIts(InFlightDiagnostic &diagnostic) const {
26412641
}
26422642

26432643
bool ContextualFailure::diagnoseMissingFunctionCall() const {
2644+
// Don't suggest inserting a function call if the function expression
2645+
// isn't written explicitly in the source code.
2646+
auto *anchor = getAsExpr(simplifyLocatorToAnchor(getLocator()));
2647+
if (!anchor || anchor->isImplicit())
2648+
return false;
2649+
26442650
if (getLocator()
26452651
->isLastElement<LocatorPathElt::UnresolvedMemberChainResult>())
26462652
return false;

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,15 +3657,17 @@ bool ConstraintSystem::repairFailures(
36573657
if (!fnType)
36583658
return false;
36593659

3660+
// If the locator isn't anchored at an expression, or the expression is
3661+
// implicit, don't try to insert an explicit call into the source code.
3662+
auto *loc = getConstraintLocator(locator);
3663+
auto *anchor = getAsExpr(simplifyLocatorToAnchor(loc));
3664+
if (!anchor || anchor->isImplicit())
3665+
return false;
3666+
36603667
// If argument is a function type and all of its parameters have
36613668
// default values, let's see whether error is related to missing
36623669
// explicit call.
36633670
if (fnType->getNumParams() > 0) {
3664-
auto *loc = getConstraintLocator(locator);
3665-
auto *anchor = getAsExpr(simplifyLocatorToAnchor(loc));
3666-
if (!anchor)
3667-
return false;
3668-
36693671
auto overload = findSelectedOverloadFor(anchor);
36703672
if (!(overload && overload->choice.isDecl()))
36713673
return false;

test/decl/var/property_wrappers.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,17 @@ struct SR_10899_Usage {
10111011
@SR_10899_Wrapper var thing: Bool // expected-error{{property type 'Bool' does not match 'wrappedValue' type 'String'}}
10121012
}
10131013

1014+
// https://bugs.swift.org/browse/SR-14730
1015+
@propertyWrapper
1016+
struct StringWrappedValue {
1017+
var wrappedValue: String
1018+
}
1019+
1020+
struct SR_14730 {
1021+
// expected-error@+1 {{property type '() -> String' does not match 'wrappedValue' type 'String'}}
1022+
@StringWrappedValue var value: () -> String
1023+
}
1024+
10141025
// SR-11061 / rdar://problem/52593304 assertion with DeclContext mismatches
10151026
class SomeValue {
10161027
@SomeA(closure: { $0 }) var some: Int = 100

0 commit comments

Comments
 (0)