8000 Shadowing class generics with method generics is confusing · Issue #33956 · dart-lang/sdk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ sdk Public

Shadowing class generics with method generics is confusing #33956

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

Closed
matanlurey opened this issue Jul 23, 2018 · 5 comments
Closed

Shadowing class generics with method generics is confusing #33956

matanlurey opened this issue Jul 23, 2018 · 5 comments
Labels
area-language Dart language related items (some items might be better tracked 8000 at github.com/dart-lang/language). closed-stale Closed as the issue or PR is assumed stale

Comments

@matanlurey
Copy link
Contributor

Reproduction case:

class Foo<T> {
  void addValues<T>(Iterable<T> values) {}
}

This causes a compile-time error:

[error] The argument type 'Iterable<T> (dart:core/iterable.dart)' can't be assigned to the parameter type 'Iterable<T> (dart:core/iterable.dart)'.

That's because the T's are different...

I do not know where to assign this (language? cfe? analyzer?)

@jonahwilliams
Copy link
Contributor

There is a similar issue in typedefs, I'm not sure if it has already been brought up:

// The T in Function shadows the T in the name.
MyCallback<T> = Function<T>(T);
// Correct version.
MyCallback2<T> = Function(T);

For example, in 2.0.0-dev.68.0 the following code produces the analyzer error:
A value of type '(String) → void' can't be assigned to a variable of type '<T>(T) → void' at main.dart:7:23 • invalid_assignment

MyCallback<T> = Function<T>(T);

void main() {
  MyCallback<String> bar = foo; 
}

void foo(String value) {}

@vsmenon
Copy link
Member
vsmenon commented Jul 24, 2018

@matanlurey I'm not getting a compile error on your snippet of code (2.0.0-dev.69.2).

@srawlins
Copy link
Member

Lol see #57713 also

@matanlurey
Copy link
Contributor Author
matanlurey commented Jul 24, 2018

@vsmenon Really? I see it internally, in DDC. Unless this was just fixed.

@a-siva a-siva added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Aug 14, 2018
@lrhn lrhn closed this as completed Apr 9, 2025
@lrhn lrhn added the closed-stale Closed as the issue or PR is assumed stale label Apr 9, 2025
@eernstg
Copy link
Member
eernstg commented Apr 9, 2025

Should be covered by this one: https://dart.dev/tools/linter-rules/avoid_shadowing_type_parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-stale Closed as the issue or PR is assumed stale
Projects
None yet
Development

No branches or pull requests

7 participants
0