Skip to content

Fix-it for repeated any and some in composition results in incorrect code #58741

Closed
@moritzdietsche

Description

@moritzdietsche

Describe the bug

When some or any appear within a composition instead of at the beginning, the compiler suggests moving the keyword to the beginning. If either of the keywords already appear at the beginning of the composition, the code after the application of the fix-it will be syntactically incorrect.

To Reproduce

Consider the following example:

protocol P1 {}
protocol P2 {}
struct S: P1, P2 {}

let _: any P1 & any P2
let x: some P1 & some P2 = S()

Applying the suggested fix-its results in the following code:

protocol P1 {}
protocol P2 {}
struct S: P1, P2 {}

let _: any any P1 & P2
let x: some some P1 & P2 = S()

Expected behavior

The compiler knows enough to propose the following code:

let _: any P1 & P2
let x: some P1 & P2 = S()

Additional context

The compiler currently also proposes moving misplaced keywords to the beginning if both some and any are used in the same composition. I think it is at least debatable if this behaviour adds any value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions