Skip to content

Change Unions/Tagged Union initialization #21737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CrazieNewb opened this issue Oct 18, 2024 · 2 comments
Closed

Change Unions/Tagged Union initialization #21737

CrazieNewb opened this issue Oct 18, 2024 · 2 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.

Comments

@CrazieNewb
Copy link

CrazieNewb commented Oct 18, 2024

Current way

const foo = Type { .Int = .{
  .signedness = .signed,
  .bits = 32,
} };

const boo: Type = .{
  .Int = .{
    .signedness = .signed,
    .bits = 32,
  }
};

Proposed way

const foo = Type.Int {       //$1
  .signedness = .signed,
  .bits = 32,
};

const boo: Type = .Int {
  .signedness = .signed,
  .bits = 32,
};

Pros:

  • Easier to read
  • Fits capitalization of enum's (treats them as a type)
  • Fits enum initialization syntax
  • Treats void type union fields as an enum

Cons:

  • New special syntax
  • Union field may be confused with a type ($1)

Extra:
const bar = Type.Int { ... } syntax might be confusing

const foo: Foo = .{
  .x = 5,      // Could be optional, or not
  .y = .A {5}  // Is clearly a union + tuple
  .z = .X      // is an enum or void union
};

const bar = Type.Int {   // Could be a union or type
  .signedness = .signed,
  .bits = 32,
};
@tauoverpi
Copy link
Contributor

See #10710 which solves this without changes to initialization for @Type where it's currently a major pain point.

@mlugg
Copy link
Member

mlugg commented Oct 18, 2024

@mlugg mlugg closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2024
@mlugg mlugg added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

3 participants