Skip to content

Proposal: Assigning to fields with short declaration notation #6842

@niemeyer

Description

@niemeyer
Is there any good reason for this to be unsupported:

    x.f, err := f()

This would be unambiguous, as it would only work if x was previously declared and err
was not.

The fact it doesn't work forces the use of:

    var err error
    x.f, err = f()

Which while okay, doesn't feel like an improvement over the former version.

As is known, there's also precedence for the use of := on reassignments, given that the
statement:

    x, err := f()

may reassign x if it was already declared in the current scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions