Skip to content

Commit 11efb7d

Browse files
committed
[Diagnostics] Added new diagnostic error string for composed property wrapper mismatch in DiagnosticsSema.def and made changes to show the new composed property wrapper mismatch type diagnostic in both CSDiagnostics.cpp and CSDiagnostics.h.
1 parent 3891dc7 commit 11efb7d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5678,8 +5678,8 @@ ERROR(wrapped_value_mismatch, none,
56785678
"property type %0 does not match 'wrappedValue' type %1",
56795679
(Type, Type))
56805680
ERROR(composed_property_wrapper_mismatch, none,
5681-
"composed wrapper type %0 does not match former 'wrappedValue' type %1",
5682-
(Type, Type))
5681+
"composed wrapper type %0 does not match the type of %1.wrappedValue, which is %2",
5682+
(Type, Type, Type))
56835683

56845684
ERROR(property_wrapper_type_access,none,
56855685
"%select{%select{variable|constant}0|property}1 "

lib/Sema/CSDiagnostics.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ bool RequirementFailure::isStaticOrInstanceMember(const ValueDecl *decl) {
348348
return decl->isStatic();
349349
}
350350

351+
bool WrappedValueMismatch::diagnoseAsError() {
352+
auto *locator = getLocator();
353+
auto elt = locator->getLastElementAs<LocatorPathElt::WrappedValue>();
354+
355+
emitDiagnostic(diag::composed_property_wrapper_mismatch, resolveType(getFromType()), elt->getType(), getToType());
356+
357+
return true;
358+
}
359+
351360
bool RequirementFailure::diagnoseAsError() {
352361
const auto *reqDC = getRequirementDC();
353362
auto *genericCtx = getGenericContext();
@@ -639,11 +648,10 @@ Optional<Diag<Type, Type>> GenericArgumentsMismatchFailure::getDiagnosticFor(
639648
return diag::cannot_convert_condition_value;
640649
case CTP_WrappedProperty:
641650
return diag::wrapped_value_mismatch;
642-
case CTP_ComposedPropertyWrapper:
643-
return diag::composed_property_wrapper_mismatch;
644651

645652
case CTP_ThrowStmt:
646653
case CTP_ForEachStmt:
654+
case CTP_ComposedPropertyWrapper:
647655
case CTP_Unused:
648656
case CTP_CannotFail:
649657
case CTP_YieldByReference:
@@ -3132,11 +3140,10 @@ ContextualFailure::getDiagnosticFor(ContextualTypePurpose context,
31323140

31333141
case CTP_WrappedProperty:
31343142
return diag::wrapped_value_mismatch;
3135-
case CTP_ComposedPropertyWrapper:
3136-
return diag::composed_property_wrapper_mismatch;
31373143

31383144
case CTP_ThrowStmt:
31393145
case CTP_ForEachStmt:
3146+
case CTP_ComposedPropertyWrapper:
31403147
case CTP_Unused:
31413148
case CTP_CannotFail:
31423149
case CTP_YieldByReference:

lib/Sema/CSDiagnostics.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,16 @@ class MissingOptionalUnwrapFailure final : public ContextualFailure {
769769
void offerForceUnwrapFixIt(const Expr *expr) const;
770770
};
771771

772+
class WrappedValueMismatch final : public ContextualFailure {
773+
public:
774+
WrappedValueMismatch(const Solution &solution, Type fromType,
775+
Type toType, ConstraintLocator *locator)
776+
: ContextualFailure(solution, fromType, toType, locator) {
777+
}
778+
779+
bool diagnoseAsError() override;
780+
};
781+
772782
/// Diagnostics for mismatched generic arguments e.g
773783
/// ```swift
774784
/// struct F<G> {}

0 commit comments

Comments
 (0)