Skip to content

Dot shorthands: Allow for shorter dot syntax to access enum values #357

Open
@rami-a

Description

@rami-a

Admin comment: this is being implemented, feature specification, dart-lang/sdk#57036, experiment flag dot-shorthands.


When using enums in Dart, it can become tedious to have to specify the full enum name every time. Since Dart has the ability to infer the type, it would be nice to allow the use of shorter dot syntax in a similar manner to Swift

The current way to use enums:

enum CompassPoint {
  north,
  south,
  east,
  west,
}

if (myValue == CompassPoint.north) {
  // do something
}

The proposed alternative:

enum CompassPoint {
  north,
  south,
  east,
  west,
}

if (myValue == .north) {
  // do something
}

Metadata

Metadata

Assignees

Labels

brevityA feature whose purpose is to enable concise syntax, typically expressible already in a longer formdot-shorthandsIssues related to the dot shorthands feature.featureProposed language feature that solves one or more problems

Type

No type

Projects

Status

Being implemented

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions