Skip to content

[Property Wrappers] Fix a crash in merge-modules with wrapped parameters. #37407

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
May 13, 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
5 changes: 5 additions & 0 deletions lib/Sema/TypeCheckPropertyWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
if (!type)
return Type();

// If the declaration came from a module file, there's no need to
// compute the auxiliary variables.
if (!var->getDeclContext()->getParentSourceFile())
return type;

// Set the interface type of each synthesized declaration.
auto auxiliaryVars = var->getPropertyWrapperAuxiliaryVariables();
auxiliaryVars.backingVar->setInterfaceType(type);
Expand Down
19 changes: 19 additions & 0 deletions validation-test/Serialization/rdar77804605.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module-path %t/WrappedParameter.swiftmodule -emit-module-source-info-path %t/WrappedParameter.swiftsourceinfo -module-name WrappedParameter -enable-testing %s
// RUN: %target-swift-frontend -merge-modules -emit-module %t/WrappedParameter.swiftmodule -module-name WrappedParameter -o %t/WrappedParameter.swiftmodule

// Make sure wrapped parameters don't crash in merge-modules when
// they were compiled with -emit-module-source-info and -enable-testing.

@propertyWrapper
struct ProjectionWrapper<Value> {
var wrappedValue: Value

var projectedValue: Self { self }

public init(projectedValue: Self) {
self = projectedValue
}
}

func test(@ProjectionWrapper value: Int) {}