-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Analyzer does not check types correctly when create a List object #34486
Comments
This is actually working as intended: The initialization of The tricky part here is that our tools may in some cases use a notion of an exact type (see #33307) to conclude that a particular downcast is guaranteed to fail at run time. We do not have a specification of exact types at this point (#33307 was created in order to make that happen), so you could say that it is a bug to use that concept at all—but I expect that we will specify exact types and we will make it an error to have some (maybe all) of these downcasts which are guaranteed to fail due to the exactness of some of the types in the given situation. This means that it would not be useful to start removing this behavior from the tools where they currently have it. In the example you show, it looks like the analyzer ascribes So the "problem" is simply that |
I think it is fair to close this as a duplicate of either:
|
Maybe the most precise approach would be to close this issue because it requests a behavior which cannot (reasonably) be expected, and not actually because it's a duplicate of anything: It requests that If we were to give @iarkh, are you happy with that resolution? |
Well, so am I correct that test with Is there a way to detect which behavior is expected for other cases (i.e. functions, etc.?) |
Right, There is no systematic way to determine which expressions have an exact type because we simply haven't specified that concept. We do have an upper bound, of course, because the static type of an expression whose value at run time can actually be a proper subtype of the statically known type can never soundly be exact. It's just that some expressions may be guaranteed to have a specific exact type, and we haven't decided whether we'd detect that: class A { const A(); }
class B implements A {}
const a = A();
main() {
foo() => a;
B b = foo(); // Error?
} A local function gets its return type by inference if it is omitted, and the returned value for How much do exact types affect your work at this point? Is it necessary to exercise them? I'd expect that we will have a whole subtopic on testing exact types when we get that topic settled, but we do need to clarify the concept first. |
@iarkh, it looks like we should close this issue with 'working as intended', so I'll do that. Please create a new issue to handle topics of this issue that you think we have not yet resolved, if needed. |
Dart SDK Version: 2.1.0-dev.4.0
OS: Windows 10 (64 bit)
The following test example creates creates a
List<List>
object and assigns it to theList<List<int>>
variable:Dart fails on this with type error, sample output is:
The problem is that the same example unexpectedly passes with dartanalyzer, no errors when I run
dartanalyzer test.dart
command with this.It seems like this result is incorrect as it's statically clear that 'List< List< dynamic>>' is not a subtype of type 'List< List< int>>'.
Also it's interesting that the following similar source code correctly fails both with analyzer and dart:
Analyzer sample output looks correctly here:
The text was updated successfully, but these errors were encountered: