Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upThe argument type 'x' can't be assigned to the parameter type 'x' #32042
Comments
This comment has been minimized.
This comment has been minimized.
(@bwilkerson FWIW this doesn't seem to crash at runtime, so maybe just an analysis issue?) |
This comment has been minimized.
This comment has been minimized.
Actually, this is the same issue - I used the code-fix to add the import and it added it was a Changing I found the other issue - it's #28895. |
DanTup
closed this
Feb 5, 2018
This comment has been minimized.
This comment has been minimized.
Yep. In Dart, two libraries are the same if, and only if, they are imported using the same URI. If two different URIs are used, even if they resolve to the same file, they will be considered to be two different libraries and the types within the file will occur twice, leading to exactly this problem. As a result, the recommendation used to be that you always use a That said, the opposite approach also works. If all URIs within a package are always relative (and two packages are not mutually recursive), then you still avoid this problem. (If you have mutually dependent packages, then using The key is to be consistent. Unfortunately, the tooling assumes the former scheme, and doesn't maintain consistency for the latter scheme. |
This comment has been minimized.
This comment has been minimized.
@bwilkerson If I understood correctly from the #28895, that issue only occurred on Windows and on Mac it was fine. I've been meaning to dig into it to see if I can debug, but haven't had chance yet (but I still have a reminder in my inbox). |
This comment has been minimized.
This comment has been minimized.
I'll be interested to hear what you find. |
This comment has been minimized.
This comment has been minimized.
Me too! Is there a convenient place I can breakpoint to inspect an error like this to see what it's comparing (so I can see how it differs between Mac/Win)? |
This comment has been minimized.
This comment has been minimized.
The way I usually tackle an issue like this is to figure out which error code defines the error you're seeing (should be defined in https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/error/codes.dart). Then find all references to the error code and put a breakpoint at the places where it's being used to create a diagnostic (there's often only one place). That usually gets me to the problematic code fairly quickly. |
This comment has been minimized.
This comment has been minimized.
@bwilkerson Great, thanks! |
This comment has been minimized.
This comment has been minimized.
maryx
commented
Feb 12, 2018
Thanks! |
This comment has been minimized.
This comment has been minimized.
@maryx I never encountered this except in Flutter where If mixing import styles would cause issues in general, the only sane way of handling that would be to entirely remove relative imports from the language. |
This comment has been minimized.
This comment has been minimized.
I think the rule I use is "never have It's not how I think about it, but it really boils down to that. Always use relative imports inside a package, always use If you seem to need to say It also holds for entry-points. If you want to run That is where the actual error is in this case—there is a reference into a package using a non-package URI—and all the changing of URIs in the package are just trying to avoid the symptoms, not the root-cause of the error. |
This comment has been minimized.
This comment has been minimized.
The analyzer currently returns a fix to use the If the guidance is to not do this then I think the analyzer should be updated to change the order (or even drop the |
This comment has been minimized.
This comment has been minimized.
The error is not due to the imports. It doesn't (well, shouldn't) matter whether a package library uses a relative or absolute path to refer to another library in the same package, it should always refer to the same library. So, the error is to have |
This comment has been minimized.
This comment has been minimized.
If I'm understanding correctly, this seems different to what @bwilkerson said?
That said, based on #28895 I think the behaviour for this may be different between Windows/Mac right now. I wanted to investigate #28895 but got stuck because of #32095 (I think they might be related, but one is user-fixable and the other is not). Personally I'd prefer that the files are treated the same (even if imported with different uris) but whatever the decision I think it must be documented so we know what's a bug and what's not. |
This comment has been minimized.
This comment has been minimized.
What @bwilkerson said is correct. A relative URI reference is not a URI. It's converted into a URI by resolving it relative to the library's own URI. If you somehow import Windows has special issues because its file system is case indifferent and URIs are not, so importing |
This comment has been minimized.
This comment has been minimized.
Ok, I think I understand you now. However, the original code that caused me to raise this is: import 'package:flutter_tools/src/vscode_validator.dart';
import 'vscode_validator.dart' The top one causes the error, the button one works. Are you saying these should be considered the same? (If so, I think this is a bug to re-open?) |
This comment has been minimized.
This comment has been minimized.
The only way that those imports can do something different if in a file that is in |
This comment has been minimized.
This comment has been minimized.
This is the import 'android/android_studio_validator.dart'; to import 'package:flutter_tools/src/android/android_studio_validator.dart'; This causes the same error. I can't see an obvious issue with any of the imports there. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
How do you start the program? I'm guessing Normally a Dart app would put its entry point in In this case, you might want to consider |
This comment has been minimized.
This comment has been minimized.
You shouldn't need to run it, since it's the analysis that's reporting the error. But if it's useful, here's my launch config (the entry is in {
"name": "Flutter Doctor",
"program": "${workspaceRoot}/bin/flutter_tools.dart",
"args": [
"doctor",
"-v"
],
"request": "launch",
"type": "dart-cli"
}, |
This comment has been minimized.
This comment has been minimized.
Ah, makes sense. I think the analyzer needs to recognize The The |
This comment has been minimized.
This comment has been minimized.
Seems like I've opened a can of worms! I'm re-opening this since it seems like something is wrong somewhere, but I'm not sure where or who is best placed to look. I did try changing all the imports in Seems like those imports in the Fuchsia files have been touched be a lot of different people so I'm not sure who is best to ping about fixing them if they're deemed wrong? |
DanTup
reopened this
Feb 12, 2018
This comment has been minimized.
This comment has been minimized.
This is still the recommendation that I give, but as you can see there are others that recommend using relative paths from libraries inside
That is, in fact, exactly what analyzer does (and has been doing for years). My only guess, at this point, is that somehow on Windows we're ending up with two URIs that have different case somewhere, despite the fact that once they've been resolved to a file path the paths are identical. @DanTup Is this a hypothesis you could investigate? One way to do that is to find the location(s) at which that error is being produced and either add a breakpoint or modify the code to use the URI rather than the file path when constructing the error message. |
This comment has been minimized.
This comment has been minimized.
Yep; this is one of the things I wanted to investigate (as mentioned above, I suspected it might be Windows-only) but hit the other Windows-analyzer issue. I think we might have a reasonable fix for that now though, so I should be able to debug further. |
This comment has been minimized.
This comment has been minimized.
(I don't currently have any access in this repo, feel free to assign it to me) |
bwilkerson
assigned
DanTup
Feb 12, 2018
bwilkerson
added
area-analyzer
p2-medium
type-bug
labels
Feb 12, 2018
DanTup
referenced this issue
Feb 13, 2018
Closed
Normalize Windows drive letters to uppercase for analysis #32133
This comment has been minimized.
This comment has been minimized.
dart-bot
closed this
in
56acaee
Feb 13, 2018
This comment has been minimized.
This comment has been minimized.
Re-opening this since the fix mentioned above was reverted and this might be a much easier case to address/fix than #32095 so it'd make sense to get out of the way first. |
DanTup
reopened this
Mar 28, 2018
This comment has been minimized.
This comment has been minimized.
DanTup
closed this
Mar 28, 2018
This comment has been minimized.
This comment has been minimized.
xorinzor
commented
Jul 19, 2018
I had this issue too, and it took me a while to figure out why. Turns out one file still had the import with the all-lowercase directory name "models", and another used the capitalized "Models". I find it strange that android-studio still accepted the import as valid, even though the directory name wasn't all-lowercase anymore. Especially since whether it was capitalized or not, it still pointed to the same file if I ctrl+clicked on it. |
This comment has been minimized.
This comment has been minimized.
@xorinzor Most likely, you are running on Windows. So, from everybody's perspective, you are referencing perfectly valid files using two different URIs, so you get two different libraries. We should probably do something about this, it's too much of a foot-gun, and it's easily detectable that it really is the same Windows file. |
This comment has been minimized.
This comment has been minimized.
xorinzor
commented
Jul 19, 2018
Yeah I'm using windows. I can understand the issue with windows not caring about capitalization, where linux does. But as you said yourself, this is really a kind of issue where it's just an absolute pain to debug the cause. So a fix would be really appreciated :) Not sure how hard it'd be to implement linux-like behaviour, where it will just error on the import if the path (case-sensitive) doesn't match. |
This comment has been minimized.
This comment has been minimized.
A Windows user generally wouldn't expect an error because they wrote Normalising paths to their file-system equiv internally when resolving the path may be an option; but it could also cause weird issues if an editor sent a request to the analysis server cased one way but the response had a different casing - so I don't think it's as simple as converting everything one way on the way in. My preferred option would be keep the case provided by the user/editor and fix all comparisons to do the right thing. There are a LOT of places this affects though - and I guess it's not just path comparisons, because it really affects the identity of types - you need to know that If it makes you feel better, this issue isn't isolated to Dart - there are so many npm packages that make assumptions about paths being case-sensitive - check how many issues reference this VS Code issue which as far as I can tell, nobody has any solid ideas for fixing. Uh, maybe that's not making anyone feel better. (probably we should continue discussion in #28895 since that's the open issue for this problem, even though the title is a little misleading since it mentions only drive letters) |
This comment has been minimized.
This comment has been minimized.
worstkiller
commented
Oct 9, 2018
For me this was the issue, different import for the same file, I was like mad from last 3-4 days and nothing seems to be working, then I read this. thanks now it's working. |
This comment has been minimized.
This comment has been minimized.
jerinho
commented
Dec 10, 2018
this too long conversation makes me dizzy. please anyone tell me which comment provide the solution? thank you. much appreciated |
This comment has been minimized.
This comment has been minimized.
@jerinho |
This comment has been minimized.
This comment has been minimized.
@jerinho Most common causes of this are mixing |
This comment has been minimized.
This comment has been minimized.
lukepighetti
commented
Dec 20, 2018
•
I'm running into this right now
I am trying to create a new class by extending Subject from rxdart within the example folder of a Flutter package. |
This comment has been minimized.
This comment has been minimized.
@lukepighetti Your error looks different:
This looks like you may have a class named |
This comment has been minimized.
This comment has been minimized.
lukepighetti
commented
Jan 2, 2019
Hey @DanTup , I was able to get around this, but I honestly can't remember how. Forgot to report back here. |
This comment has been minimized.
This comment has been minimized.
Glad you sorted it, but do shout if you see it again and can't figure it out :-) |
This comment has been minimized.
This comment has been minimized.
emuthomi
commented
Jan 18, 2019
•
I have landed here after spending an hour or so fighting this:
type casting didn't help as suggested but after digging deeper it's when I saw where the error was:
Turned out to be an uppercase/lowercase typo in one of the imports. |
DanTup commentedFeb 5, 2018
I think we've seen this before on Windows and believed it to be imports mixing 'package:' and relative paths, however I've just hit this today on a framework type:
Note that the types are the same:
The source code is this revision:
DanTup/flutter@601655b
Originally the
VsCodeValidator.installedValidators
returned a List (not Iterable) but I got an equally confusing message (can't assign the list to an argument of iterable) so I change it to iterable while debugging and then it still complained.I can try this on my Mac later, but I wouldn't be surprised if this was Windows-only given the previous similar error we had was.