Skip to content

Analyzer issues error 'invalid override' in case of covariant argument and inherited implementation #34329

Open
@alexmarkov

Description

@alexmarkov

Test:

class A {}
class B extends A {}

class Base {
  void f(B arg) {}
}

abstract class Interface {
  void f(covariant A arg);
}

class C extends Base implements Interface {}

Analyzer output:

Analyzing foo.dart...
  error • Base class introduces an invalid override. The type of 'Base.f' ('(B) → void') isn't a subtype of 'Interface.f' ('(A) → void') at foo.dart:13:9 • strong_mode_invalid_method_override_from_base
1 error found.

The following similar test does not produce an error:

class A {}
class B extends A {}

class Base implements Interface {
  void f(B arg) {}
}

abstract class Interface {
  void f(covariant A arg);
}

class C extends Base {}

CFE doesn't flag any errors in both cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)dart-model-analyzer-specIssues with the analyzer's implementation of the language spectype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions