Closed
Description
With the constructor-tearoffs
experiment enabled, the following code is rejected by the CFE but accepted by the analyzer:
typedef X<_> = Class;
typedef Z<_, __> = Class;
class Class {
static Class get instance => Class();
}
main() {
Z<X, X>.instance;
}
(Note: this code is based on https://dart-review.googlesource.com/c/sdk/+/211420)
The CFE's error message is:
../../tmp/proj/test.dart:10:11: Error: Cannot access static member on an instantiated generic class.
Try removing the type arguments or placing them after the member name.
Z<X, X>.instance;
^^^^^^^^
Based on the discussion at dart-lang/language#1802 (specifically this comment), I believe that the CFE's behavior is correct: Z<X, X>.instance
should be interpreted as an attempt to tear off a constructor named instance
from the class named Class
. Class
does contain a member named instance
, but it's not a constructor, it's a static getter. Therefore this should be an error.