Skip to content

ParameterElementImpls returned from GenericFunctionTypeElement's parameters method always return as equal to each other #30146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jcollins-g opened this issue Jul 12, 2017 · 5 comments
Labels
analyzer-api Issues that impact the public API of the analyzer package area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jcollins-g
Copy link
Contributor

jcollins-g commented Jul 12, 2017

In the case where GenericFunctionTypeElement is being used in a new style generic function type declaration, e.g.:

/// A typedef with the new style generic function syntax.
typedef NewGenericTypedef<T> = List<S> Function<S>(T, int, bool);

the corresponding GenericFunctionTypeElement correctly generates three different parameter objects, one each for T, int, and bool.

However, each of them have the same hashCode and compare as equal to each other, which can confuse dartdoc's internal object cache. This results in all three looking like 'T'.

@jcollins-g jcollins-g added the legacy-area-analyzer Use area-devexp instead. label Jul 12, 2017
@jcollins-g
Copy link
Contributor Author

Tested with analyzer package 0.30.0.

@jcollins-g jcollins-g changed the title ParameterElementImpls returned from GenericFunctionTypeElement's parameters method have bad hashCodes ParameterElementImpls returned from GenericFunctionTypeElement's parameters method always return as equal to each other Jul 12, 2017
@bwilkerson bwilkerson added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 19, 2017
@jcollins-g
Copy link
Contributor Author

jcollins-g commented Sep 26, 2017

Similarly, this problem crops up in cases like:

/// This class has a complicated type situation.
abstract class TypedFunctionsWithoutTypedefs {
  void Function(T1, T2) getAFunctionReturningVoid<T1, T2>(
      void callback(T1 argument1, T2 argument2));
}

The return type winds up being documented as Function(T1, T1) due to dartdoc's object cache being subverted.

These patterns are starting to be used in the SDK and elsewhere now so the impact of this bug is increasing.

@jmesserly
Copy link

I believe this happens because they have no name. The == and hashCode for Elements looks at the fully qualified name, essentially enclosing scope+item name. So they'll compare equal because they all have no parameter name.

I think TypeParameterElements have a similar problem when we make synthetic ones (for synthetic function types). In that case, they've got their name but they don't have an enclosing scope, so every synthetic type parameter with the same name will compare equal to every other one (two unrelated variables T and T will compare equal). Some notes on that issue here: #29778 (comment)

@jcollins-g
Copy link
Contributor Author

I think I've convinced myself that dropping caching for Parameter ModelElements is safe in dartdoc, so I will do that to work around this problem.

@jcollins-g
Copy link
Contributor Author

I'm having to work around this in another way for dart-lang/dartdoc#1835.

@srawlins srawlins added the analyzer-api Issues that impact the public API of the analyzer package label Jun 17, 2020
@srawlins srawlins added P3 A lower priority bug or feature request and removed P2 A bug or feature request we're likely to work on labels Apr 17, 2023
@johnniwinther johnniwinther added area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. and removed legacy-area-analyzer Use area-devexp instead. labels Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-api Issues that impact the public API of the analyzer package area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants