Skip to content

Commit 9eaad63

Browse files
authored
Merge pull request #77689 from JanBaig/issue-65500
[CSGen] Fix compiler crash when property wrapper applied to a param lacks wrappedValue initializer
2 parents 9665b0d + 8af3aef commit 9eaad63

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

lib/Sema/CSGen.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5060,18 +5060,35 @@ ConstraintSystem::applyPropertyWrapperToParameter(
50605060
anchor = apply->getFn();
50615061
}
50625062

5063-
if (argLabel.hasDollarPrefix() && (!param || !param->hasExternalPropertyWrapper())) {
5063+
auto recordPropertyWrapperFix = [&](ConstraintFix *fix) -> TypeMatchResult {
50645064
if (!shouldAttemptFixes())
50655065
return getTypeMatchFailure(locator);
50665066

50675067
recordAnyTypeVarAsPotentialHole(paramType);
50685068

5069-
auto *loc = getConstraintLocator(locator);
5070-
auto *fix = RemoveProjectedValueArgument::create(*this, wrapperType, param, loc);
50715069
if (recordFix(fix))
50725070
return getTypeMatchFailure(locator);
50735071

50745072
return getTypeMatchSuccess();
5073+
};
5074+
5075+
// Incorrect use of projected value argument
5076+
if (argLabel.hasDollarPrefix() &&
5077+
(!param || !param->hasExternalPropertyWrapper())) {
5078+
auto *loc = getConstraintLocator(locator);
5079+
auto *fix =
5080+
RemoveProjectedValueArgument::create(*this, wrapperType, param, loc);
5081+
return recordPropertyWrapperFix(fix);
5082+
}
5083+
5084+
// Missing wrapped value initializer
5085+
auto wrapperInfo = param->getAttachedPropertyWrapperTypeInfo(0);
5086+
if (!argLabel.hasDollarPrefix() && !wrapperInfo.wrappedValueInit &&
5087+
param->hasExternalPropertyWrapper()) {
5088+
auto *loc = getConstraintLocator(locator);
5089+
auto *fix = UsePropertyWrapper::create(
5090+
*this, param, /*usingProjection=*/true, paramType, wrapperType, loc);
5091+
return recordPropertyWrapperFix(fix);
50755092
}
50765093

50775094
if (argLabel.hasDollarPrefix()) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// https://github.com/swiftlang/swift/issues/65500
4+
5+
@propertyWrapper
6+
struct Wrapper {
7+
var wrappedValue: Bool { true }
8+
init(wrappedValue: Bool, er: Void) {}
9+
10+
var projectedValue: Bool { true }
11+
init(projectedValue: Bool) {}
12+
}
13+
14+
func test(@Wrapper x: Bool) {}
15+
test(x: false)
16+
// expected-error@-1 {{cannot convert value 'x' of type 'Bool' to expected type 'Wrapper', use wrapper instead}}{{9-9=$}}

0 commit comments

Comments
 (0)