sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Front end: Confusing error message for void as superclass

Open eernstg opened this issue 6 years ago • 2 comments

Consider the following program:

class C extends void {}
void main() {}

With dart from commit 61f5e8845433088b7eca22c8f3cce4fa10acccd2 we get the following errors:

n062.dart:1:17: Error: Type 'void' can't be used here.
Try removing 'void' keyword or replace it with 'var', 'final', or a type.
class C extends void {}
                ^^^^
n062.dart:1:17: Error: Type 'void' not found.
class C extends void {}
                ^^^^

This is confusing, given that void is used as a superclass and that is an error, but we can't say var or final in that position. Also, not found is a surprise.

eernstg avatar Nov 27 '19 19:11 eernstg

implements void gets a similar treatment.

eernstg avatar Nov 28 '19 11:11 eernstg

The analyzer produces two diagnostics:

  • "Expected a type name."
  • "Classes can only extend other classes."

For the 'implements' case the first diagnostic is the same, but the second is tailored to it being an implements clause.

There really only needs to be one diagnostic here, and the second is better (especially since void is a type).

bwilkerson avatar Jun 06 '25 22:06 bwilkerson