Skip to content

extension types not being recognised as objects #60838

Open
@jellynoone

Description

@jellynoone
import 'dart:collection';

void main() {
  ['Hi', '', 'Hello'].map(FullString.fromOr).nonNulls; // The getter 'nonNulls' isn't defined for the type...
  <String?>['Hi', '', 'Hello'].nonNulls; // works as expected
}

extension type FullString._(String value) {
  static FullString? fromOr(String value) {
    if (value.isEmpty) return null;
    return FullString._(value);
  }
}

Invoking dart analyze main.dart produces the above error. However, I cannot reproduce this using dartpad so it might be something wrong with my installation.

Dart version: Dart SDK version: 3.8.1 (stable) (Wed May 28 00:47:25 2025 -0700) on "macos_arm64"

Metadata

Metadata

Labels

area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.feature-extension-typesImplementation of the extension type feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions