Skip to content

[analyzer] No error reported when trying to access a static getter via a type literal with type arguments #47006

Closed
@stereotype441

Description

@stereotype441

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.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work ondart-model-analyzer-specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions