Skip to content

Unnecessary checks on declared-covariant parameters #35317

@sjindel-google

Description

@sjindel-google

Consider this (simplified) example:

class RenderObject {}
class RenderClipPath extends RenderObject {}
class RenderCustomPaint extends RenderObject {}

class RenderObjectWidget {
  void didUnmountRenderObject(covariant RenderObject _) {}
}

class ClipPath extends RenderObjectWidget {
  void didUnmountRenderObject(RenderClipPath _) {}
}

class CustomPaint extends RenderObjectWidget {
  void didUnmountRenderObject(RenderCustomPaint _) {}
}

RenderObjectWidget.didUnmountRenderObject will have a type-check for it's argument even though it provably cannot fail. In general, if a parameter is declared covariant on a method which is not seen in the interface of any supertypes of its enclosing class, it doesn't need a type-check.

I'm working on fixing this on the VM-site, but the CFE should distinguish between parameters labeled "covariant" by the user and parameters which need to be checked due to declared-covariance.

@mraleph

Metadata

Metadata

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.customer-vmlegacy-area-front-endLegacy: Use area-dart-model instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions