Skip to content

Constructor like syntax is parsed as method if the name is wrong #31001

Open
@scheglov

Description

@scheglov
class A {
  B() : super();
}
library;
import self as self;
import "dart:core" as core;

class A extends core::Object {
  default constructor •() → void
    : super core::Object::•()
    ;
  abstract method B() → dynamic;
}
static const field dynamic #errors = const <dynamic>["file:///test.dart:2:16: Error: Can't have initializers: B\n  B() : super();\n               ^"]/* from null */;

There is inconsistency between Analyzer parser and Fasta.

Analyzer reports an error and treats B() : super() as A() : super() because there is : after parameters.

Fasta says that this is a method, and it should not have constructor initializers.

I think Analyzer's behavior is a bit better because we lose less nodes when we recover this way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions