Skip to content
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

Eliminate fuzzy arrows #29630

Closed
leafpetersen opened this issue May 16, 2017 · 4 comments
Closed

Eliminate fuzzy arrows #29630

leafpetersen opened this issue May 16, 2017 · 4 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). language-strong-mode-polish soundness

Comments

@leafpetersen
Copy link
Member

leafpetersen commented May 16, 2017

In Dart 1.0, dynamic is used as both top and bottom. In strong mode, we made it top almost everywhere, except that for function typed variables (only) we made dynamic on parameter types mean bottom in order to enable certain code patterns:

typedef Arity1(x);
typedef Arity2(x, y);

void test(Function f, List args) {
  if (f is Arity1) {  // Matches any 1 argument function
   f(args[0]);
  } else if (f is Arity2) {  // Matches any 2 argument function
    f(args[0], args[1]);
  }
}

Since we how have a name for bottom in the language (Null), we can support this pattern directly:

typedef Arity1 = Function(Null);
typedef Arity2 = Function(Null, Null);

void test(Function f, List args) {
  if (f is Arity1) {  // Matches any 1 argument function
   (f as dynamic)(args[0]);
  } else if (f is Arity2) {  // Matches any 2 argument function
    (f as dynamic)(args[0], args[1]);
  }
}

The original motivation for fuzzy arrows is gone, and it continues to cause user confusion and soundness difficulties. This is a tracking bug for the elimination of all remaining uses of them, following by the deprecation and elimination of the feature.

A hint has been added to the analyzer to warn on uses of this feature:

  hint • A function of type '(int) → bool' can't be assigned to a variable of type '(dynamic) → bool' at /Users/leafp/tmp/test.dart:5:13 • uses_dynamic_as_bottom

This hint will become an error once code is fixed up appropriately.

An example:

bool listEqual(List a, List b, bool compare(x, y)) {...};
listEqual([1], [2], (int x, int y) => x == y);

This code will now cause a hint, since it uses a function taking two integer arguments in a context that might provide it with anything.

You can fix code like this by removing the types on the function or moving them into the body:

listEqual([1], [2], (_x, _y) { int x = _x; int y = _y; x == y;});

but it is often better to change the API to make the original call site valid:

bool listEqual<S, T>(List<S> a, List<T> b, bool compare(S x, T y)) {...}
listEqual([1], [2], (int x, int y) => x == y);

Related:
#29299
#29295

@leafpetersen
Copy link
Member Author

Filed dart-lang/test#674

munificent added a commit to dart-lang/bazel_worker that referenced this issue Nov 3, 2017
Context: dart-lang/sdk#29630

I also fixed a few places to use the real generic method syntax while
I was at it.

I bumped the version to 0.2.0-dev since my change is technically
breaking -- it changes the return type of TestStdinAsync.controller.
If you don't feel that will actually break any real users, I can do
0.1.5-dev instead.

This needs to roll into Google after I land it. If you'd like me to
publish this, let me know and I'll do 0.1.5 instead.
jakemac53 pushed a commit to dart-lang/bazel_worker that referenced this issue Nov 3, 2017
Context: dart-lang/sdk#29630

- fixes a few places to use the real generic method syntax
- bumps version to 0.1.5
munificent added a commit to dart-lang/coverage that referenced this issue Nov 8, 2017
These will become an arrow in Dart 2.0. See this bug for more context:

  dart-lang/sdk#29630

I also fixed a couple of unused variable warnings while I was at it.

I bumped the version number in the pubspec. This is technically a
potentially breaking change because the signatures of createHitmap() and
mergeHitmaps() are more precise now. The only code I could find calling
that was in flutter_tools and that seems to be happy with the change.
If you'd rather I keep the old version, let me know.
munificent added a commit to dart-archive/observe that referenced this issue Nov 8, 2017
These will become an error in Dart 2.0. Context here:

  dart-lang/sdk#29630

I also went ahead and fixed a few other minor warnings while I was in
here.
cbracken pushed a commit to dart-lang/coverage that referenced this issue Nov 9, 2017
These will become an arrow in Dart 2.0. See this bug for more context:

  dart-lang/sdk#29630

I also fixed a couple of unused variable warnings while I was at it.

I bumped the version number in the pubspec. This is technically a
potentially breaking change because the signatures of createHitmap() and
mergeHitmaps() are more precise now. The only code I could find calling
that was in flutter_tools and that seems to be happy with the change.
If you'd rather I keep the old version, let me know.
alorenzen pushed a commit to angulardart/angular that referenced this issue Jan 17, 2018
…row purposes.

Using dynamic as bottom ("fuzzy arrow") will become an error in Dart 2.0. dart-lang/sdk#29630

PiperOrigin-RevId: 182127013
alorenzen pushed a commit to angulardart/angular that referenced this issue Jan 17, 2018
…row purposes.

Using dynamic as bottom ("fuzzy arrow") will become an error in Dart 2.0. dart-lang/sdk#29630

PiperOrigin-RevId: 182127013
alorenzen pushed a commit to angulardart/angular that referenced this issue Jan 17, 2018
…row purposes.

Using dynamic as bottom ("fuzzy arrow") will become an error in Dart 2.0. dart-lang/sdk#29630

PiperOrigin-RevId: 182127013
nshahan pushed a commit to angulardart/angular_components that referenced this issue Jan 18, 2018
…ries.

Using dynamic as bottom will become an error in Dart 2.0. dart-lang/sdk#29630

PiperOrigin-RevId: 182013886
nshahan pushed a commit to angulardart/angular_components that referenced this issue Jan 18, 2018
Using dynamic as bottom will become an error in Dart 2.0. dart-lang/sdk#29630

PiperOrigin-RevId: 182020806
nshahan pushed a commit to angulardart/angular_components that referenced this issue Jan 19, 2018
…ries.

Using dynamic as bottom will become an error in Dart 2.0. dart-lang/sdk#29630

PiperOrigin-RevId: 182013886
nshahan pushed a commit to angulardart/angular_components that referenced this issue Jan 19, 2018
Using dynamic as bottom will become an error in Dart 2.0. dart-lang/sdk#29630

PiperOrigin-RevId: 182020806
alorenzen pushed a commit to angulardart/angular that referenced this issue Jan 26, 2018
…e argument of [callback]. Generated template.dart files fill in a type for the argument of [callback], so using dynamic here results in a "uses dynamic as bottom" error.

See discussion here: dart-lang/sdk#29630

PiperOrigin-RevId: 183131552
alorenzen pushed a commit to angulardart/angular that referenced this issue Jan 26, 2018
…e argument of [callback]. Generated template.dart files fill in a type for the argument of [callback], so using dynamic here results in a "uses dynamic as bottom" error.

See discussion here: dart-lang/sdk#29630

PiperOrigin-RevId: 183131552
alorenzen pushed a commit to angulardart/angular that referenced this issue Jan 29, 2018
…e argument of [callback]. Generated template.dart files fill in a type for the argument of [callback], so using dynamic here results in a "uses dynamic as bottom" error.

See discussion here: dart-lang/sdk#29630

PiperOrigin-RevId: 183131552
alorenzen pushed a commit to angulardart/angular that referenced this issue Jan 29, 2018
…e argument of [callback]. Generated template.dart files fill in a type for the argument of [callback], so using dynamic here results in a "uses dynamic as bottom" error.

See discussion here: dart-lang/sdk#29630

PiperOrigin-RevId: 183131552
alorenzen pushed a commit to angulardart/angular that referenced this issue Jan 29, 2018
…e argument of [callback]. Generated template.dart files fill in a type for the argument of [callback], so using dynamic here results in a "uses dynamic as bottom" error.

See discussion here: dart-lang/sdk#29630

PiperOrigin-RevId: 183131552
alorenzen pushed a commit to angulardart/angular that referenced this issue Jan 30, 2018
…e argument of [callback]. Generated template.dart files fill in a type for the argument of [callback], so using dynamic here results in a "uses dynamic as bottom" error.

See discussion here: dart-lang/sdk#29630

PiperOrigin-RevId: 183131552
@leafpetersen
Copy link
Member Author

This is done.

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). language-strong-mode-polish soundness
Projects
None yet
Development

No branches or pull requests

4 participants