Skip to content

[Property Wrappers] Fix a diagnostic crash when a parameter has a wrapped value mismatch. #37093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6354,10 +6354,12 @@ Type ParamDecl::getVarargBaseTy(Type VarArgT) {

AnyFunctionType::Param ParamDecl::toFunctionParam(Type type) const {
if (!type) {
type = getInterfaceType();

if (hasExternalPropertyWrapper()) {
type = getPropertyWrapperBackingPropertyType();
} else {
type = getInterfaceType();
if (auto wrapper = getPropertyWrapperBackingPropertyType()) {
type = wrapper;
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3034,10 +3034,12 @@ void TypeChecker::checkParameterList(ParameterList *params,
(void) param->getPropertyWrapperInitializerInfo();

auto *SF = param->getDeclContext()->getParentSourceFile();
param->visitAuxiliaryDecls([&](VarDecl *auxiliaryDecl) {
if (!isa<ParamDecl>(auxiliaryDecl))
DeclChecker(param->getASTContext(), SF).visitBoundVariable(auxiliaryDecl);
});
if (!param->isInvalid()) {
param->visitAuxiliaryDecls([&](VarDecl *auxiliaryDecl) {
if (!isa<ParamDecl>(auxiliaryDecl))
DeclChecker(param->getASTContext(), SF).visitBoundVariable(auxiliaryDecl);
});
}
}

// For source compatibilty, allow duplicate internal parameter names
Expand Down
12 changes: 12 additions & 0 deletions test/Sema/property_wrapper_parameter_invalid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,15 @@ func testMissingWrapperType() {
return
}
}

@propertyWrapper
struct OptionalWrapper<Value> { // expected-note {{'Value' declared as parameter to type 'OptionalWrapper'}}
var wrappedValue: Value?
var projectedValue: Self { self }
init(wrappedValue: Value?) { self.wrappedValue = wrappedValue }
init(projectedValue: Self) { self = projectedValue }
}

// expected-error@+2 {{generic parameter 'Value' could not be inferred}} expected-note@+2 {{}}
// expected-error@+1 {{property type 'Int' does not match 'wrappedValue' type 'Value?'}}
func testWrappedValueMismatch(@OptionalWrapper value: Int) {}