Skip to content

[Sema] Restore 5.10 implicit self behavior prior to Swift 6 mode #74260

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 2 commits into from
Jun 11, 2024

Conversation

hamishknight
Copy link
Contributor

Unfortunately we've encountered another source breaking case here:

class C {
  func method() {}

  func foo() {
    Task { [weak self] in
      Task {
        method()
      }
    }
  }
}

In 5.10 we'd only do the unqualified lookup for self when directly in a weak self closure, but with the implicit self rework (#70575), we'd start using the weak self here, leading to a type-checker error.

At this point, adding more edge cases to the existing logic is going to make things much more complicated. Instead, reinstate the 5.10 implicit self lookup behavior and diagnostic logic, switching over to the new logic only under Swift 6 mode.

rdar://129475277

@hamishknight
Copy link
Contributor Author

FYI @calda, unfortunately I think we have to keep the old behavior prior to Swift 6 mode

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

Copy link
Contributor

@calda calda left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks for the fix

Make it a bit clearer which function actually cares
about the closure it's handed.
Unfortunately we've encountered another source
breaking case here:

```
class C {
  func method() {}

  func foo() {
    Task { [weak self] in
      Task {
        method()
      }
    }
  }
}
```

In 5.10 we'd only do the unqualified lookup for
`self` when directly in a `weak self` closure,
but with the implicit self rework, we'd start
using the `weak self` here, leading to a
type-checker error.

At this point, adding more edge cases to the
existing logic is going to make things much more
complicated. Instead, reinstate the 5.10 implicit
self lookup behavior and diagnostic logic,
switching over to the new logic only under Swift 6
mode.

rdar://129475277
@hamishknight hamishknight force-pushed the another-implicit-self-fix branch from ce2a871 to fe272e6 Compare June 10, 2024 19:29
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight merged commit 592462b into swiftlang:main Jun 11, 2024
5 checks passed
@hamishknight hamishknight deleted the another-implicit-self-fix branch June 11, 2024 10:04
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