Skip to content

augment keyword analyzes fine but is not recognized and produces error during compile #60039

@timmaffett

Description

@timmaffett

This simple example passes analysis fine but produces errors on attempting to run/compile.

// @dart = 3.7

class Person {
  Person(this.name);

  final String name;
}

augment class Person {
  @override
  String toString() {
    return 'Person(name: $name)';
  }
}

void main() {
  var person =  Person('John Doe');

  print(person);
}

Output results:

dart --version

C:\src\superbasic>dart --version
Dart SDK version: 3.8.0-24.0.dev (dev) (Wed Jan 22 12:05:43 2025 -0800) on "windows_x64"

dart analyze basic_test3.dart

C:\src\superbasic>dart analyze basic_test3.dart
Analyzing basic_test3.dart...
No issues found!

dart run basic_test3.dart

C:\src\superbasic>dart run basic_test3.dart
basic_test3.dart:9:1: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
Try adding the name of the type of the variable or the keyword 'var'.
augment class Person {
^^^^^^^
basic_test3.dart:9:1: Error: Expected ';' after this.
augment class Person {
^^^^^^^
basic_test3.dart:9:15: Error: 'Person' is already declared in this scope.
augment class Person {
              ^^^^^^
basic_test3.dart:3:7: Context: Previous declaration of 'Person'.
class Person {
      ^^^^^^
basic_test3.dart:12:27: Error: The getter 'name' isn't defined for the class 'Person#1#0'.
 - 'Person#1#0' is from 'basic_test3.dart'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'name'.
    return 'Person(name: $name)';
                          ^^^^
basic_test3.dart:17:17: Error: Can't use 'Person' because it is declared more than once.
  var person =  Person('John Doe');
                ^

Executing dart --enable-experiment=augmentations run basic_test3.dart produces the same results (on the off chance it was somehow not enabling augmentations by version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cfe-feature-augmentationImplement augmentation features in the CFEfeature-augmentationsImplementation of the augmentations featurelegacy-area-front-endLegacy: Use area-dart-model instead.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