Language: Should we have an error or warning for a static method on an unnamed extension?

Created on 9 Oct 2019  路  2Comments  路  Source: dart-lang/language

extension on String {
  static String cannotCall() => '';
}

As far as I can tell there is no way to invoke cannotCall given this definition, so it's not useful to define it. Should we make this an error or warning?

extension-methods question

Most helpful comment

It can be invoked from within the extension, so I expect it won't be an error.

It's a TODO for the analyzer to detect it as dead code if it isn't being invoked.

All 2 comments

It can be invoked from within the extension, so I expect it won't be an error.

It's a TODO for the analyzer to detect it as dead code if it isn't being invoked.

Agree. There is nothing inherently wrong with having local static helper functions in scope and used by the extension members.

It's dead code, like any other static on a private class, if it's not actually used by the containing library, and the analyzer should be able to recognize that normally.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mit-mit picture mit-mit  路  3Comments

leonsenft picture leonsenft  路  4Comments

Cat-sushi picture Cat-sushi  路  3Comments

lrhn picture lrhn  路  4Comments

leafpetersen picture leafpetersen  路  3Comments