Skip to content

Commit 03d869a

Browse files
committed
[Diagnostics] Extract invalid result type from overload choice
Instead of threading it through the constraint system all the way to a diagnostic, let's extract it from overload choice instead.
1 parent 5b55ea1 commit 03d869a

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

include/swift/Sema/CSFix.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,23 +2314,19 @@ class AllowUnsupportedRuntimeCheckedCast final
23142314

23152315
class AllowInvalidStaticMemberRefOnProtocolMetatype final
23162316
: public ConstraintFix {
2317-
Type ResultType;
2318-
23192317
AllowInvalidStaticMemberRefOnProtocolMetatype(ConstraintSystem &cs,
2320-
Type resultType,
23212318
ConstraintLocator *locator)
23222319
: ConstraintFix(cs,
23232320
FixKind::AllowInvalidStaticMemberRefOnProtocolMetatype,
2324-
locator),
2325-
ResultType(resultType) {}
2321+
locator) {}
23262322

23272323
public:
23282324
std::string getName() const override {
23292325
return "allow invalid static member reference on a protocol metatype";
23302326
}
23312327

23322328
static AllowInvalidStaticMemberRefOnProtocolMetatype *
2333-
create(ConstraintSystem &cs, Type resultType, ConstraintLocator *locator);
2329+
create(ConstraintSystem &cs, ConstraintLocator *locator);
23342330
};
23352331

23362332
} // end namespace constraints

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7199,6 +7199,10 @@ bool InvalidMemberRefOnProtocolMetatype::diagnoseAsError() {
71997199
if (!overload)
72007200
return false;
72017201

7202+
auto resultTy = overload->openedType;
7203+
if (auto *fnType = resultTy->getAs<FunctionType>())
7204+
resultTy = fnType->getResult();
7205+
72027206
auto *member = overload->choice.getDeclOrNull();
72037207
assert(member);
72047208

@@ -7207,7 +7211,7 @@ bool InvalidMemberRefOnProtocolMetatype::diagnoseAsError() {
72077211

72087212
emitDiagnostic(diag::type_does_not_conform_in_member_ref_on_protocol_type,
72097213
member->getDescriptiveKind(), member->getName(),
7210-
MetatypeType::get(protocolTy), ResultType);
7214+
MetatypeType::get(protocolTy), resultTy);
72117215
emitDiagnosticAt(member, diag::decl_declared_here, member->getName());
72127216
return true;
72137217
}

lib/Sema/CSDiagnostics.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,12 +2486,10 @@ class UnsupportedRuntimeCheckedCastFailure final
24862486
/// `bar` can't be referenced from `P.Protocol` base because its result type
24872487
/// `Int` doesn't conform to `Foo`.
24882488
class InvalidMemberRefOnProtocolMetatype final : public FailureDiagnostic {
2489-
Type ResultType;
2490-
24912489
public:
2492-
InvalidMemberRefOnProtocolMetatype(const Solution &solution, Type resultType,
2490+
InvalidMemberRefOnProtocolMetatype(const Solution &solution,
24932491
ConstraintLocator *locator)
2494-
: FailureDiagnostic(solution, locator), ResultType(resultType) {}
2492+
: FailureDiagnostic(solution, locator) {}
24952493

24962494
bool diagnoseAsError() override;
24972495
};

lib/Sema/CSFix.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,14 +1941,13 @@ bool AllowUnsupportedRuntimeCheckedCast::diagnose(const Solution &solution,
19411941

19421942
bool AllowInvalidStaticMemberRefOnProtocolMetatype::diagnose(
19431943
const Solution &solution, bool asNote) const {
1944-
InvalidMemberRefOnProtocolMetatype failure(solution, ResultType,
1945-
getLocator());
1944+
InvalidMemberRefOnProtocolMetatype failure(solution, getLocator());
19461945
return failure.diagnose(asNote);
19471946
}
19481947

19491948
AllowInvalidStaticMemberRefOnProtocolMetatype *
19501949
AllowInvalidStaticMemberRefOnProtocolMetatype::create(
1951-
ConstraintSystem &cs, Type resultType, ConstraintLocator *locator) {
1950+
ConstraintSystem &cs, ConstraintLocator *locator) {
19521951
return new (cs.getAllocator())
1953-
AllowInvalidStaticMemberRefOnProtocolMetatype(cs, resultType, locator);
1952+
AllowInvalidStaticMemberRefOnProtocolMetatype(cs, locator);
19541953
}

0 commit comments

Comments
 (0)