Skip to content

Sema: Allow closure parameter lists to reference opaque parameter declarations #77491

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
Nov 9, 2024

Conversation

slavapestov
Copy link
Contributor

A function declaration cannot have an opaque parameter type appearing in consuming position:

func f(_: (some P) -> ()) {}

However, we should skip this check for a closure, because if the closure's parameter list references an opaque parameter declaration, it means something else: namely, the inferred type of the closure refers to an opaque parameter from an outer scope. That's allowed.

This unnecessary prohibition has been there ever since the check was added, but only for multi-statement closures, so nobody seemed to notice.

When #76473 made it so we always call TypeChecker::checkParameterList(), this exposed the problem in a single-expression closure in an existing project.

Fixes rdar://139237671.

…larations

A function declaration cannot have an opaque parameter type appearing in
consuming position:

    func f(_: (some P) -> ()) {}

However, we should skip this check for a closure, because if the
closure's parameter list references an opaque parameter declaration,
it means something else: namely, the inferred type of the closure
refers to an opaque parameter from an outer scope. That's allowed.

This unnecessary prohibition has been there ever since the check was
added, but only for multi-statement closures, so nobody seemed to
notice.

When swiftlang#76473 made it so we always
call TypeChecker::checkParameterList(), this exposed the problem in a
single-expression closure in an existing project.

Fixes rdar://139237671.
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@slavapestov slavapestov merged commit b5af518 into swiftlang:main Nov 9, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants