Skip to content

Allow binding named fields without names? #59

@osa1

Description

@osa1

Currently I can't do this:

test(x: [A(val: U32), B(val: Str)])
    match x:
        ~A(val): printStr(val.toStr())
        ~B(val): printStr(val)

Because the fields are named, I have to do ~A(val = val) if I want to use the same name as the field, or ~A(val = anotherName) if I want to rename.

Instead we should probably allow the code above.

One potential issue is that, when looking at the pattern, it will be impossible to tell whether the pattern is matching A(val: ...) or A(...) (i.e. whether the variable is matching a named field without giving it a new name, or a positional field).

I doubt it's going to be a problem in practice though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions