Skip to content

[Extension Methods] Unable to recognize an extension method on Object? #60973

Open
@AlexV525

Description

@AlexV525

There are no options to import the extension method when writing specific code.

Image

Steps to reproduce

object_extensions.dart
extension NullableObjectExtension on Object? {
  Map<String, dynamic> asJson() => (this as Map).cast<String, dynamic>();
}
snippet.dart
typedef ObjectFactory<T> = T Function(Object? v);

class Rep<T> {
  const Rep(this.data);

  factory Rep.fromJson(
    Map<String, Object?> json,
    ObjectFactory<T> factory,
  ) {
    return Rep<T>(factory(json));
  }

  final T data;
}

void test() {
  final map = <String, Object?>{};
  final rep = Rep.fromJson(map, (v) => v.asJson());  // <-- unchecked_use_of_nullable_value
}

Version

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-quick-fixIssues with analysis server (quick) fixestype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions