Skip to content

Add struct constructor expressions #17

@kodek16

Description

@kodek16

Currently to create a struct with certain values used as its fields you need to first default-initialize a new struct, and then assign the field values manually:

struct Foo {
   x: int;
   y: string;
}

fun main() {
  var f: Foo;
  f.x = 42;
  f.y = "hello";
}

This is quite cumbersome (and even more so in expression contexts), and would be much better handled by a special syntax that fills the fields directly.

The added expression syntax could look like this:

var f = Foo { x: 42, y: "hello" };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions