Skip to content

Improve diagnostic when attempting to use += to append a single element #65609

Open
@hamishknight

Description

@hamishknight

For e.g:

struct S {}
var arr: [S] = []
arr += S() // error: Operator function '+=' requires that 'S' conform to 'Sequence'

The diagnostic isn't too helpful. More helpful would be suggesting using [S()] (which could be a general fix where we attempt to match types using an array instead), though I think the ideal suggestion in this case would be to use append instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsimprovementoperatorsFeature: operatorsswift 5.9type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions