Skip to content

Commit 4e2b67c

Browse files
committed
[NFC] Resolved merge conflict in CSSimplify.cpp after making changes to improve error handling for composed wrapped value mismatches
1 parent b3f0442 commit 4e2b67c

File tree

10 files changed

+34
-34
lines changed

10 files changed

+34
-34
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 the type of %1.wrappedValue, which is %2",
5682-
(Type, Type, Type))
5681+
"composed wrapper type %0 does not match type of '%1.wrappedValue', which is %2",
5682+
(Type, StringRef, Type))
56835683

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

include/swift/Sema/CSFix.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,11 @@ enum class FixKind : uint8_t {
322322
/// even though result type of the reference doesn't conform
323323
/// to an expected protocol.
324324
AllowInvalidStaticMemberRefOnProtocolMetatype,
325-
326-
/// Allow the wrappedValue type of the outermost property
327-
/// wrapper of a composed property wrapper to mismatch
328-
/// the type of its innermost property wrapper.
325+
326+
/// Allow the wrappedValue type of any property wrapper that is a
327+
/// part of a composed property wrapper to mismatch the type of
328+
/// another property wrapper that is a part of the same composed
329+
/// property wrapper.
329330
AllowWrappedValueMismatch,
330331
};
331332

include/swift/Sema/ConstraintLocator.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ class ConstraintLocator : public llvm::FoldingSetNode {
212212
/// Determine whether this locator points to the generic parameter.
213213
bool isForGenericParameter() const;
214214

215-
/// Determine whether this locator points to the outer
216-
/// property wrapper's type for a given composed property
217-
/// wrapper.
215+
/// Determine whether this locator points to any of the
216+
/// property wrappers' types for a given composed property
217+
/// wrapper, with the exception of the innermost property wrapper's
218+
/// type.
218219
bool isForWrappedValue() const;
219220

220221
/// Determine whether this locator points to the element type of a
@@ -360,10 +361,11 @@ class ConstraintLocator : public llvm::FoldingSetNode {
360361

361362
/// If this locator points to generic parameter return its type.
362363
GenericTypeParamType *getGenericParameter() const;
363-
364-
/// If this locator points to the outer property wrapper's
365-
/// type for a given composed property wrapper.
366-
TypeBase *getWrappedValue() const;
364+
365+
/// If this locator points to any of the property wrappers' types
366+
/// for a given composed property wrapper, with the exception
367+
/// of the innermost property wrapper's type.
368+
Type getWrappedValue() const;
367369

368370
/// Produce a profile of this locator, for use in a folding set.
369371
static void Profile(llvm::FoldingSetNodeID &id, ASTNode anchor,
@@ -703,13 +705,12 @@ class LocatorPathElt::GenericParameter final : public StoredPointerElement<Gener
703705

704706
class LocatorPathElt::WrappedValue final : public StoredPointerElement<TypeBase> {
705707
public:
706-
WrappedValue(TypeBase *type)
707-
: StoredPointerElement(PathElementKind::WrappedValue, type) {
708+
WrappedValue(Type type)
709+
: StoredPointerElement(PathElementKind::WrappedValue, type.getPointer()) {
710+
assert(type.getPointer() != nullptr);
708711
}
709712

710-
TypeBase *getType() const {
711-
return getStoredPointer();
712-
}
713+
Type getType() const { return getStoredPointer(); }
713714

714715
static bool classof(const LocatorPathElt *elt) {
715716
return elt->getKind() == PathElementKind::WrappedValue;

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ SIMPLE_LOCATOR_PATH_ELT(InstanceType)
9696
/// Also contains the generic parameter type itself.
9797
CUSTOM_LOCATOR_PATH_ELT(GenericParameter)
9898

99-
/// The former wrappedValue type for a property wrapper.
99+
/// The wrappedValue type for a property wrapper.
100100
///
101101
/// Must equal the property declaration's property wrapper type.
102102
CUSTOM_LOCATOR_PATH_ELT(WrappedValue)

lib/Sema/CSDiagnostics.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,10 @@ bool RequirementFailure::isStaticOrInstanceMember(const ValueDecl *decl) {
350350

351351
bool WrappedValueMismatch::diagnoseAsError() {
352352
auto *locator = getLocator();
353-
auto elt = locator->getLastElementAs<LocatorPathElt::WrappedValue>();
353+
auto elt = locator->castLastElementTo<LocatorPathElt::WrappedValue>();
354354

355-
emitDiagnostic(diag::composed_property_wrapper_mismatch, resolveType(getFromType()), elt->getType(), getToType());
355+
emitDiagnostic(diag::composed_property_wrapper_mismatch, getFromType(),
356+
resolveType(elt.getType())->getString(), getToType());
356357

357358
return true;
358359
}

lib/Sema/CSFix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ ContextualMismatch *ContextualMismatch::create(ConstraintSystem &cs, Type lhs,
374374

375375
bool AllowWrappedValueMismatch::diagnose(const Solution &solution, bool asError) const {
376376
WrappedValueMismatch failure(solution, getFromType(), getToType(), getLocator());
377-
return(failure.diagnoseAsError());
377+
return failure.diagnoseAsError();
378378
}
379379

380380
AllowWrappedValueMismatch *AllowWrappedValueMismatch::create(ConstraintSystem &cs,

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3613,7 +3613,7 @@ static bool generateWrappedPropertyTypeConstraints(
36133613
} else {
36143614
// The former wrappedValue type must be equal to the current wrapper type
36153615
auto *locator = cs.getConstraintLocator(
3616-
typeExpr, LocatorPathElt::WrappedValue(wrapperType.getPointer()));
3616+
typeExpr, LocatorPathElt::WrappedValue(wrapperType));
36173617
wrapperType =
36183618
cs.replaceInferableTypesWithTypeVars(rawWrapperType, locator);
36193619
cs.addConstraint(ConstraintKind::Equal, wrapperType, wrappedValueType, locator);

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11260,6 +11260,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1126011260
case FixKind::AllowUnsupportedRuntimeCheckedCast:
1126111261
case FixKind::AllowAlwaysSucceedCheckedCast:
1126211262
case FixKind::AllowInvalidStaticMemberRefOnProtocolMetatype:
11263+
case FixKind::AllowWrappedValueMismatch:
1126311264
case FixKind::RemoveExtraneousArguments: {
1126411265
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1126511266
}
@@ -11397,11 +11398,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1139711398

1139811399
return SolutionKind::Solved;
1139911400
}
11400-
11401-
case FixKind::AllowWrappedValueMismatch: {
11402-
if (recordFix(fix)) return SolutionKind::Error;
11403-
return SolutionKind::Solved;
11404-
}
1140511401

1140611402
case FixKind::UseSubscriptOperator:
1140711403
case FixKind::ExplicitlyEscaping:

lib/Sema/ConstraintLocator.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ GenericTypeParamType *ConstraintLocator::getGenericParameter() const {
223223
castLastElementTo<LocatorPathElt::GenericParameter>().getType() : nullptr;
224224
}
225225

226-
TypeBase *ConstraintLocator::getWrappedValue() const {
227-
return isForWrappedValue() ?
228-
castLastElementTo<LocatorPathElt::WrappedValue>().getType() : nullptr;
226+
Type ConstraintLocator::getWrappedValue() const {
227+
return isForWrappedValue()
228+
? castLastElementTo<LocatorPathElt::WrappedValue>().getType()
229+
: Type();
229230
}
230231

231232
void ConstraintLocator::dump(SourceManager *sm) const {
@@ -283,7 +284,7 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
283284
case WrappedValue: {
284285
auto wrappedValueElt = elt.castTo<LocatorPathElt::WrappedValue>();
285286
out << "composed property wrapper type '"
286-
<< wrappedValueElt.getType()->getString(PO) << "'";
287+
<< wrappedValueElt.getType()->getString(PO) << "'";
287288
break;
288289
}
289290
case ApplyArgument:

test/decl/var/property_wrappers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,9 @@ struct TestComposition {
10971097
@WrapperD<WrapperC, Int, String> @WrapperC var p4: Int?
10981098
@WrapperD<WrapperC, Int, String> @WrapperE var p5: Int // expected-error{{generic parameter 'Value' could not be inferred}}
10991099
// expected-note@-1 {{explicitly specify the generic arguments to fix this issue}}
1100-
// expected-error@-2 {{composed wrapper type 'WrapperE<Int>' does not match the type of 'WrapperD<WrapperC<_>, Int, String>'.wrappedValue, which is 'WrapperC<Value>'}}
1100+
// expected-error@-2 {{composed wrapper type 'WrapperE<Int>' does not match type of 'WrapperD<WrapperC<Value>, Int, String>.wrappedValue', which is 'WrapperC<Value>'}}
11011101

1102-
@Wrapper<String> @Wrapper var value: Int // expected-error{{composed wrapper type 'Wrapper<Int>' does not match the type of 'Wrapper<String>'.wrappedValue, which is 'String'}}
1102+
@Wrapper<String> @Wrapper var value: Int // expected-error{{composed wrapper type 'Wrapper<Int>' does not match type of 'Wrapper<String>.wrappedValue', which is 'String'}}
11031103

11041104
func triggerErrors(d: Double) { // expected-note 6 {{mark method 'mutating' to make 'self' mutable}} {{2-2=mutating }}
11051105
p1 = d // expected-error{{cannot assign value of type 'Double' to type 'Int?'}} {{8-8=Int(}} {{9-9=)}}

0 commit comments

Comments
 (0)