Skip to content

Super void parameter throws This expression has type 'void' and can't be used #60861

Open
@FMorschel

Description

@FMorschel

Repro:

class A {
  A(this.value);
  A.named({this.value});
  final int? value;
}

// Reason for the constructors to all have the same parameters would be consistency and tear-off possibility
class B extends A {
  B(super.value);
  B.named({super.value}) : super.named();
}

// Here everything is fine
class C extends A {
  C(void value) : super(0);
  C.named({void value}) : super.named();
}

class D extends C {
  D(super.value);
  D.named({super.value}) : super.named();
}

void main() {
  D(0);
  D.named(value: 0);
}

Error:

lib/a.dart:19:18: Error: This expression has type 'void' and can't be used.
a.dart:19
  D.named({super.value}) : super.named();
                 ^
Old

The problem here is that there is no analyzer warning at D.named({super.value}), and the error happens when running. This can be fixed if we simply replace super.value with void value, but that is harder IMO.

The problem here (considering lrhn's first comment on this issue) is that the CFE is wrong. We should be able to compile the code. The analyzer shows no diagnostics and this is WAI.

Metadata

Metadata

Labels

P2A bug or feature request we're likely to work onarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.cfe-dysfunctionalitiesIssues for the CFE not behaving as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions