Skip to content

Nonusable Declarations #60251

@RohitSaily

Description

@RohitSaily

It is possible to have the following code without any warnings

extension on Never
{     int get instanceMember=>
            0;
}

The instanceMember declaration can never be usable and is guaranteed to be a dead declaration/code. It would be helpful if a static warning were displayed to notify developers. This is not a matter of correctness but enhancing developer experience and enforcing the semantics of Never.

Warnings should not be reported for accessible static members e.g. the following should have no warning

extension A on Never
{      static void a()
             {}
}

As @FMorschel stated in this thread, this also applies to extension types e.g.

extension type A(Never n)
      {}

Should produce a warning because the primary constructor can never be used. This would also apply to instance member declarations added to the extension type.


A somewhat related issue regarding reporting warnings for any usage of Never objects can be found #60247. For more information see dart-lang/language#4279, it contains discussion related to this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-warningIssues with the analyzer's Warning codestype-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