dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.19k stars 1.57k forks source link

Analyzer auto-completes members on "Never.^" non-ideally #52962

Closed matanlurey closed 10 months ago

matanlurey commented 1 year ago

Simple example

On most types (i.e. String):

void main() {
  String.^
}

Screenshot 2023-07-17 at 4 43 31 PM

but for Never:

Screenshot 2023-07-17 at 4 44 09 PM

Why file this issue?

Good question. One could say this is such a rare or even unusable concept and the priority of this should be P12. However, this makes using a cute-little namespace pattern in Dart a bit ugly:

extension Fruits on Never {
  const apple = 'apple';
  const grapes = 'grapes';
  const watermelon = 'watermelon';
}

void main() {
  // Auto-completes first with hashCode and runtimeType, and then Fruits.apple third.
  print(Fruits.^);
}
lrhn commented 1 year ago

Not sure I understand the example. The const declarations are not valid (have to be static, there are no instance constant variables), you can't access statics of an extension through the on type, and you can't access instance getters on a type object.

If they are supposed to be static, I don't think the priority has anything to do with the type Never. But I can be wrong about that.

matanlurey commented 1 year ago

you can't access statics of an extension through

Sure you can:

void main() {
  print(Presidents.abe);
}

extension Presidents on Never {
  static const abe = 'Abraham';
  static const george = 'George';
  static const jefferson = 'Jefferson';
}
lrhn commented 1 year ago

That's not "through the on type". That's just accessing statics on the extension name directly, so it's not on Never, and should (I hope) not be related to the Never type at all.

I'd expect that it is the same for any extension type, that statics on an extension type hey lower priority than instance methods on the Type object, possibly because extension instance methods get lower precedence than interface instance methods. (But that is just guessing, until I get to test it.)