Skip to content

Commit bb70f0e

Browse files
authored
Merge pull request #27235 from theblixguy/fix/SR-11381_5.1
[5.1] [PropertyWrappers] Fix a bug with property type being overwritten with wrong type
2 parents e05f800 + 238446f commit bb70f0e

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,7 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
26322632
emptyLocator);
26332633
return propertyType;
26342634
}
2635-
2635+
26362636
// Otherwise, compute the wrapped value type directly.
26372637
return computeWrappedValueType(wrappedVar, initType);
26382638
}
@@ -2654,10 +2654,10 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
26542654
// is the initialization of the property wrapper instance.
26552655
initType = cs.getType(expr);
26562656

2657-
// Add a conversion constraint between the pattern type and the
2657+
// Add an equal constraint between the pattern type and the
26582658
// property wrapper's "value" type.
2659-
cs.addConstraint(ConstraintKind::Conversion, patternType,
2660-
getPatternInitType(&cs), Locator, /*isFavored*/true);
2659+
cs.addConstraint(ConstraintKind::Equal, patternType,
2660+
getPatternInitType(&cs), Locator, /*isFavored*/ true);
26612661
} else {
26622662
// The initializer type is the type of the pattern.
26632663
initType = patternType;

test/decl/var/property_wrappers.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,3 +1131,17 @@ struct UseNonMutatingProjectedValueSet {
11311131
x = 42 // expected-error{{cannot assign to property: 'self' is immutable}}
11321132
}
11331133
}
1134+
1135+
// SR-11381
1136+
1137+
@propertyWrapper
1138+
struct SR_11381_W<T> {
1139+
init(wrappedValue: T) {}
1140+
var wrappedValue: T {
1141+
fatalError()
1142+
}
1143+
}
1144+
1145+
struct SR_11381_S {
1146+
@SR_11381_W var foo: Int = nil // expected-error {{'nil' requires a contextual type}}
1147+
}

0 commit comments

Comments
 (0)