Skip to content

bug: Not all names are legal wrt. to dot-shorthands notation #62085

@nielsenko

Description

@nielsenko
final class Weird {
  final List<int> encodings;
  Weird.encodings(this.encodings);
}

void main() {
  // ignore: unused_local_variable
  Weird d = .encodings([]);
}

run dart analyze main.dart you get

➜ dart analyze main.dart
Analyzing main.dart...                 0.1s

  error • main.dart:8:14 • The static method or constructor 'encodings' isn't defined for the context type 'Weird'. Try correcting
          the name to the name of an existing static method or constructor, or defining a static method or constructor named 'encodings'. •
          dot_shorthand_undefined_member

1 issue found.

Rename the named ctor to something else:

final class Weird {
  final List<int> encodings;
  Weird.encodings2(this.encodings);
}

void main() {
  // ignore: unused_local_variable
  Weird d = .encodings2([]);
}

You get no analysis errors?!

➜ dart analyze main.dart
Analyzing main.dart...                 0.1s
No issues found!

Environment:

❯ dart info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

#### General info

- Dart 3.10.1 (stable) (Tue Nov 18 11:02:31 2025 -0800) on "macos_x64"
- on macos / Version 26.1 (Build 25B78)
- locale is en-DK

#### Process info

| Memory |  CPU | Elapsed time | Command line                                                                     |
| -----: | ---: | -----------: | -------------------------------------------------------------------------------- |
| 730 MB | 0.0% |     21:22:10 | dart language-server --protocol lsp                                              |
| 185 MB | 0.0% |     22:54:53 | dart language-server --protocol lsp                                              |
| 102 MB | 0.0% |     22:50:30 | dart language-server --protocol lsp                                              |
| 274 MB | 0.0% |        44:22 | dart language-server --protocol=lsp                                              |
| 242 MB | 0.0% |        44:22 | dart language-server --protocol=lsp                                              |
| 212 MB | 0.0% |        25:07 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.122.0 |
|  22 MB | 0.0% |     21:22:10 | dart mcp-server                                                                  |
|  15 MB | 0.0% |     22:54:54 | dart mcp-server                                                                  |
|  16 MB | 0.0% |     22:50:30 | dart mcp-server                                                                  |
|  26 MB | 0.0% |        25:07 | dart tooling-daemon --machine                                                    |

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.feature-dot-shorthandsImplementation of the dot shorthands feature.model-discrepancyDiscrepancies between analyzer and cfemodel-featuresGeneral feature work in the analyzer and CFE.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions