Skip to content

[static-extensions] Use the same kind of erasure with the on type as dot shorthands? #4683

@eernstg

Description

@eernstg

The dot shorthand feature relies on the declaration denoted by a type schema to find a declaration even in the case where the context type is a union type (FutureOr or ?). For example:

import 'dart:async';

class A {
  static A get fresh => A();
}

void main() {
  FutureOr<A?>? a = .fresh;
}

This issue is a proposal that we should use the same rule with static extensions when we determine whether a given on type denotes a declaration:

extension E on FutureOr<A?> {
  factory new name() => A(); // OK.
}

void main() {
  A.name(); // OK.
}

The motivation would be that a developer may wish to introduce some extension members on, say, C?, and they also want to include some constructors of C in the same extension (e.g., in order to avoid having to mention two names in show or hide clauses). Also, the alignment with dot shorthands would make this kind of erasure unsurprising for many developers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    small-featureA small feature which is relatively cheap to implement.static-extensionsIssues about the static-extensions feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions