Skip to content

Primary constructors with curly brackets for user-named fields #3198

Closed
@Cat-sushi

Description

@Cat-sushi

For consistency with records, like

typedef R = (int, {int a, int b});
R r = /* R */(1, a:2, b:3);
main(){
  print(r.$1);
  print(r.a);
  print(r.b);
}

, I think that primary constructors should have syntax with curly brackets for user-named fields, like

data class D(int, {int a, int b});
D d = D(1, a:2, b:3);
main(){
  print(d.$1);
  print(d.a);
  print(d.b);
}

.

My understanding is that data classes are records with class names, both of them share characteristics of simple, immutable, unboxing optimization friendly, without persistent identity, and with structural equality, in other words value types, then syntactic consistency is important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions