Sdk: Re-enable whereType after generic methods are turned on in all tools

Created on 8 Mar 2018  Â·  10Comments  Â·  Source: dart-lang/sdk

The behavior of the new whereType method is silently broken on platforms that have not yet turned on generic methods (i.e. dart2js and the VM). We will make this method throw until generic methods are turned on.

See https://github.com/dart-lang/sdk/issues/32423 for context.

Once generic methods are turned on, we need to re-enable this.

P1 area-library

Most helpful comment

Shouldn't this have a milestone? I was surprised when using the Dart 2 documentation, which says this function exists, and then finding it broken.

All 10 comments

We can make the method fail only when generic methods are not working.
We should probably do the same to the cast which silently doesn't actually cast.

We can make the method fail _only_ when generic methods are not working.

This is a little risky because we commonly develop/test with DDC and then release with dart2js. We strive for coverage with dart2js as well but it doesn't always work out. It would definitely be much better than silently ignoring the dynamic.

We should probably do the same to the cast which silently doesn't actually cast.

I haven't been able to come up with a where that would matter. The runtimes where it won't cast are also the ones that won't care that it isn't the correct reified type... right?

There certainly is danger in doing something like:

if (users is List<AdminUser>) {
  ...
}

Or

// In runtimes without obsfucation/minification.
if ('$users.runtimeType' == 'List<AdminUser>') {
  ...
}

but for better or worse, that's been the case since Dart 1.0.0. The .cast<...> function is in the same class of issues. I wish we were a little more clear about what it did/didn't do it in the various runtimes, but its all good.

Shouldn't this have a milestone? I was surprised when using the Dart 2 documentation, which says this function exists, and then finding it broken.

I just got burned by this as well on the latest dev release. Is this not making it into 2.0? If not, this should really be documented as there's no mention whatsoever about this feature not being supported and we currently recommend using it on the Effective Dart page.

cc @kwalrath

This is making it into Dart 2.0, just as soon as we stop running Dart 1 code (or, hopefully, slightly before).

The function was disabled because people were using it while developing in DDC, and the got burned by it not working when compiling on dart2js in Dart 1 mode. It was considered too much of a foot-gun, so it was temporarily disabled.
We are now running almost all code in Dart 2 mode, with only a few white-listed holdovers, so maybe it's time to flip it back on. (And I just heard that the white-list is now empty, so let's GO!)

@bkonyi I'm going to add a note to that page, linking to this issue.

@leafpetersen @lrhn – can we get moving on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matanlurey picture matanlurey  Â·  3Comments

DartBot picture DartBot  Â·  3Comments

matanlurey picture matanlurey  Â·  3Comments

sgrekhov picture sgrekhov  Â·  3Comments

ranquild picture ranquild  Â·  3Comments