-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Strong-mode should fill omitted type parameters with type bound instead of dynamic? #26310
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
Comments
cc/ @leafpetersen |
This might be an instance of #26265 . Are you seeing this in the IDE or the command line? If in the IDE, can you wait until analysis stabilizes, edit the file in a way that causes re-analysis (say insert and remove a space from the middle of the word 'Rectangle'), and see if it fixes itself? |
yeah and FYI, the original fix was in #25877 |
I'm seeing this in command line ( Note: also happens with |
If I define my own local class Rectangle<T extends num> {}
// OK
foo(Rectangle r) => bar(r);
bar(Rectangle<num> r) => null; For the record: it does know that the bound is num, as the following code fails: import 'dart:math';
Rectangle<String> r;
// ^
// [error] 'String' does not extend 'num' |
FYI, I'm seeing "no issues found" on your original example. Using a bleeding_edge build (864b64f) |
@jmesserly can you double check? I see the issue with latest dev release, and with bleeding edge analyzer. |
Oh sorry! I was hitting the bug where running from the wrong directory, --strong is ignored :( |
I can reproduce this using the command-line analyzer, but if I open the same file in my IDE (in a project that enables strong mode) I don't get an error. If I hover over either occurrence of
it reports that To save time running this down, does anyone know where the substitution of the bounds for the missing type argument is happening? |
TypeSystem.instantiateToBounds is where we handle the difference. It needs to be called any time we want the "default instantiation behavior". For |
IIRC, it should be happening on this line: sdk/pkg/analyzer/lib/src/generated/resolver.dart Line 9747 in fc55cb9
|
Thanks! That's exactly where it should happen. But for reasons I don't understand yet, the type parameter for Rectangle doesn't have a bound (which explains why it isn't being used). |
Oh crazy! Shot in the dark: maybe it fails to deserialize it from the SDK summary or something like that? |
Thought about that. Konstantin says we're not using summaries anywhere yet. Also, I can see in the debugger where we're resolving and setting the bound (though I haven't been able to find where it's being cleared), which tells me we're not using summaries because we're following the old code path to resolve dart:math. |
I believe that this is caused by a bug in the task descriptions: we're not requiring that the bounds for classes in imported libraries be resolved before resolving types in the importing library. But as Konstantin pointed out in #26265, there are also ordering issues even when the types are all defined in the same compilation unit. |
Closing this as a duplicate of #26265 since I think that bug captures the issue here. If there's something additional about this bug that's not captured there, feel free to reopen. |
Context: I found many usages of
class Rectangle<T extends num>
with the non-generic raw typeRectangle
. Seems like it's treated by strong-mode asRectangle<dynamic>
, while it would seem it could / should beRectangle<num>
:(tested with
1.16.0-dev.2.0
)The text was updated successfully, but these errors were encountered: