Skip to content

Analyzer comment indicates a factory constructor can have a return type #60563

Closed
@srawlins

Description

@srawlins

The comment on ConstructorDeclaration.redirectedConstructor (public API) says:

The type of object being created.

This can be different than the type in which the constructor is being
declared if the constructor is the implementation of a factory
constructor.

I'm not sure if that was ever true, but it isn't true now. (It'd be a cool feature.)

This code:

class C {
  factory D C.foo() {
    return D();
  }
}

class D implements C {}

results in several errors, among them:

The name of a factory constructor must be the same as the name of the immediately enclosing class.

And this code:

class C {
  D factory C.foo() {
    return D();
  }
}

class D implements C {}

results in one error:

Factory constructors cannot have a return type.

Looking at the call sites of ConstructorDeclarationImpl, the value of returnType is always a SimpleIdentifier for the type name, in either a named or unnamed constructor.

Metadata

Metadata

Assignees

Labels

area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-documentationA request to add or improve documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions