Skip to content

Commit 8cc7f09

Browse files
committed
[SE-0258] More tests and hardening for property wrapper composition
1 parent e857852 commit 8cc7f09

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4662,7 +4662,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
46624662

46634663
// If the base type is optional because we haven't chosen to force an
46644664
// implicit optional, don't try to fix it. The IUO will be forced instead.
4665-
if (auto dotExpr = dyn_cast<UnresolvedDotExpr>(locator->getAnchor())) {
4665+
if (auto dotExpr =
4666+
dyn_cast_or_null<UnresolvedDotExpr>(locator->getAnchor())) {
46664667
auto baseExpr = dotExpr->getBase();
46674668
auto resolvedOverload = getResolvedOverloadSets();
46684669
while (resolvedOverload) {
@@ -4682,8 +4683,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
46824683
auto innerTV = createTypeVariable(locator,
46834684
TVO_CanBindToLValue |
46844685
TVO_CanBindToNoEscape);
4685-
Type optTy = getTypeChecker().getOptionalType(
4686-
locator->getAnchor()->getSourceRange().Start, innerTV);
4686+
Type optTy = getTypeChecker().getOptionalType(SourceLoc(), innerTV);
46874687
SmallVector<Constraint *, 2> optionalities;
46884688
auto nonoptionalResult = Constraint::createFixed(
46894689
*this, ConstraintKind::Bind,

test/decl/var/property_wrappers.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,15 +799,30 @@ struct WrapperC<Value> {
799799
}
800800
}
801801

802+
@propertyWrapper
803+
struct WrapperD<Value, X, Y> { // expected-note{{property wrapper type 'WrapperD' declared here}}
804+
var value: Value
805+
}
806+
807+
@propertyWrapper
808+
struct WrapperE<Value> {
809+
var value: Value
810+
}
811+
802812
struct TestComposition {
803813
@WrapperA @WrapperB @WrapperC var p1: Int?
804814
@WrapperA @WrapperB @WrapperC var p2 = "Hello"
815+
@WrapperD<WrapperE, Int, String> @WrapperE var p3: Int?
816+
@WrapperD<WrapperC, Int, String> @WrapperC var p4: Int?
817+
@WrapperD<WrapperC, Int, String> @WrapperE var p5: Int // expected-error{{property type 'Int' does not match that of the 'value' property of its wrapper type 'WrapperD<WrapperC, Int, String>'}}
805818

806819
func triggerErrors(d: Double) {
807820
p1 = d // expected-error{{cannot assign value of type 'Double' to type 'Int?'}}
808821
p2 = d // expected-error{{cannot assign value of type 'Double' to type 'String?'}}
822+
p3 = d // expected-error{{cannot assign value of type 'Double' to type 'Int?'}}
809823

810824
$p1 = d // expected-error{{cannot assign value of type 'Double' to type 'WrapperA<WrapperB<WrapperC<Int>>>'}}
811825
$p2 = d // expected-error{{cannot assign value of type 'Double' to type 'WrapperA<WrapperB<WrapperC<String>>>'}}
826+
$p3 = d // expected-error{{cannot assign value of type 'Double' to type 'WrapperD<WrapperE<Int?>, Int, String>'}}
812827
}
813828
}

0 commit comments

Comments
 (0)