FuelLabs / FuelLabs/sway

Add support for the use of `..` in structs

Open
#1,817 5 comments 0 reactions 0 assignees View on GitHub
compiler: frontend compiler: parser language feature P: medium team:compiler
Dominant language
Rust
Stars
61.4k
Forks
5.4k
Avg merge
3h 33m
Merged PRs (30d)
4

Description

# Motivation

Currently, when a `struct` is instantiated every field must be specified.

As a user I may not care about every field when creating a new `struct` and thus it would be nice to have a default value take place for the fields that are not specified.

This would be done using the `..` syntax similar to `Rust`.

```rust
struct MyStruct {
field1: type1,
field2: type2,
field3: type3,
}

let my_struct = MyStruct { field2: value2, .. };
```

Related: #1568

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing related issue #1568 and the compiler's existing struct-instantiation handling. The issue names no files or tests; done would require agreed semantics and support for the proposed `..` syntax so unspecified fields receive default values.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.