Skip to content
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

syntactic_sugar rule breaks optional existential any return values #5277

Closed
2 tasks done
AttilaTheFun opened this issue Oct 14, 2023 · 1 comment · Fixed by #5278
Closed
2 tasks done

syntactic_sugar rule breaks optional existential any return values #5277

AttilaTheFun opened this issue Oct 14, 2023 · 1 comment · Fixed by #5278
Labels

Comments

@AttilaTheFun
Copy link

New Issue Checklist

Describe the bug

Protocols with primary associated types used as optional return values cannot use the ? syntactic sugar.

Given:

protocol Foo<Bar> {
  associatedtype Foo
  func foo() -> Foo
}

A function that returns an optional Foo must be written:

func buildFoo<T>() -> Optional<any Foo<T>>

But the syntactic_sugar rule autocorrects this to:

func buildFoo<T>() -> any Foo<T>?

Which results in the compiler error:

use of protocol Foo<Bar>? must be written Optional<any Foo<Bar>>

To address this, the syntactic_sugar rule should not suggest this correction for optionals with an existential after their opening angle bracket (some or any).

@SimplyDanny
Copy link
Collaborator

The proper fixes proposed by the syntactic_sugar rule would be (any Foo<T>)? and (some Foo<T>)?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants