Skip to content

Documentation on how to narrow types when using super parameters #50647

Open
@kaboc

Description

@kaboc
class Foo {
  const Foo(this.value);

  final int? value;
}

class Bar extends Foo {
  const Bar(int value)
      : _value = value,
        super(value);

  final int _value;

  @override
  int get value => _value;
}

Bar accepts only a value of type int, while Foo accepts int?. The use_super_parameter rule warns there although it is intentional that I've avoided super.value so that the value of Bar never becomes null.

It is possible to suppress the warning with the // ignore: use_super_parameter comment, but it'll be better if the intention is considered. Is it too much for the analyzer to handle?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-documentationPrefer using 'type-documentation' and a specific area label.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions