Skip to content

Commit 8c1a959

Browse files
authored
Merge pull request #29795 from vukrado/SR-11964-bad-diagnostic-mismatched-numeric-types
[CSSimplify] Increment impact for DefineMemberBasedOnUse when base type is any function type
2 parents c59f1aa + a570e93 commit 8c1a959

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6322,6 +6322,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
63226322
// not a match in this case.
63236323
auto impact =
63246324
locator->findLast<LocatorPathElt::UnresolvedMember>() ? 2 : 1;
6325+
6326+
// Impact is higher if the the base type is any function type
6327+
// because function types can't have any members other than self
6328+
if (baseObjTy->is<AnyFunctionType>()) {
6329+
impact += 10;
6330+
}
6331+
63256332
if (recordFix(fix, impact))
63266333
return SolutionKind::Error;
63276334

test/Constraints/diagnostics.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,3 +1385,23 @@ class ClassWithPropContainingSetter {
13851385
set { return 1 } // expected-error {{unexpected non-void return value in void function}}
13861386
}
13871387
}
1388+
1389+
// https://bugs.swift.org/browse/SR-11964
1390+
struct Rect {
1391+
let width: Int
1392+
let height: Int
1393+
}
1394+
1395+
struct Frame {
1396+
func rect(width: Int, height: Int) -> Rect {
1397+
Rect(width: width, height: height)
1398+
}
1399+
1400+
let rect: Rect
1401+
}
1402+
1403+
func foo(frame: Frame) {
1404+
frame.rect.width + 10.0 // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'Double'}}
1405+
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (Int, Int)}}
1406+
1407+
}

0 commit comments

Comments
 (0)