Skip to content

syntactic_sugar rule breaks optional existential any return values #5277

Description

@AttilaTheFun

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected and reproducible misbehavior.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions