From 41e2411752fff9233778a8d5be873ecdf9d34c74 Mon Sep 17 00:00:00 2001 From: Vuk Radosavljevic Date: Wed, 12 Feb 2020 14:49:19 -0600 Subject: [PATCH 1/2] [CSSimplify] Increment impact by 1 for DefineMemberBasedOnUse when base type is any function type --- lib/Sema/CSSimplify.cpp | 7 +++++++ test/Constraints/diagnostics.swift | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index f93b4adc66bc5..0bae5ec5aa991 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -6322,6 +6322,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint( // not a match in this case. auto impact = locator->findLast() ? 2 : 1; + + // Impact is higher if the the base type is any function type + // because function types can't have any members other than self + if (baseObjTy->getDesugaredType()->is()) { + impact += 1; + } + if (recordFix(fix, impact)) return SolutionKind::Error; diff --git a/test/Constraints/diagnostics.swift b/test/Constraints/diagnostics.swift index b9ffb4a484c80..3a29a100151bf 100644 --- a/test/Constraints/diagnostics.swift +++ b/test/Constraints/diagnostics.swift @@ -1385,3 +1385,23 @@ class ClassWithPropContainingSetter { set { return 1 } // expected-error {{unexpected non-void return value in void function}} } } + +// https://bugs.swift.org/browse/SR-11964 +struct Rect { + let width: Int + let height: Int +} + +struct Frame { + func rect(width: Int, height: Int) -> Rect { + Rect(width: width, height: height) + } + + let rect: Rect +} + +func foo(frame: Frame) { + frame.rect.width + 10.0 // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'Double'}} + // expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (Int, Int)}} + +} From a570e9330f5736ac87844a264d5acb8e43f6423d Mon Sep 17 00:00:00 2001 From: Vuk Radosavljevic Date: Wed, 12 Feb 2020 17:29:22 -0600 Subject: [PATCH 2/2] Removed using desugard type and changed impact from 1 to 10 --- lib/Sema/CSSimplify.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 0bae5ec5aa991..955d4fa44eed8 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -6325,8 +6325,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint( // Impact is higher if the the base type is any function type // because function types can't have any members other than self - if (baseObjTy->getDesugaredType()->is()) { - impact += 1; + if (baseObjTy->is()) { + impact += 10; } if (recordFix(fix, impact))