-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer reports mismatched types on Windows due to drive letter casing #28895
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
The problem seems to be how you refer to your entry-point and the relation between the libraries. If you refer to So either run/analyze using a package URI or stop doing absolute imports. I recommend the latter in any case. It's an unnecessary complication to hard-code your own package name into internal references, at least unless absolutely necessary. If nothing else, it makes it harder to rename the package, and it doesn't do anything good. That is, either run/analyze it as In the linked Dart-Code example, you say that changing the package-URIs work, and it is a solution. As for Dart-Code, they might want to refer to files that are part of a package by its package-URI, not its file-location, if that is possible. |
That filename is what comes back from the analysis server and then gets passed to VS Code in the errors list; nowhere in the repro is importing it like this (nor do we pass it to the analyzer; only the workspace root). That path is (presumably) constructed by the analysis service based on the analysis root we pass to it; I don't believe there's anything I can change here to fix this.
Dart Code doesn't invoke the analyzer directly; it spawns the analysis server from the snapshot in the SDK and then passes it the root folder. We don't parse any of the code at all. We just say "here's a folder of Dart code" and the analysis server gives us all the errors; how pubspec/lib/imports are handled are all internal to the analysis service. I believe this issue could be repro'd entirely without Dart Code (though I'm surprised it apparently doesn't occur in Atom, which uses the same service; though I don't have Atom to test it myself). It's possible this code is incorrect and should be using relative paths; though the author expected it to work (and at first glance, I would to; though I'm not all that experience with Dart). I'm struggling to see how I can fix this in Dart Code though :( |
That sounds like it's probably an analyzer problem then. If the analyzer sees the The error report does need to show the file name - the analysis server can handle large directories with multiple package structures, so a package URI doesn't uniquely identify the file with the problem. |
Yes, that's exactly what analysis server does. And as a consequence, we advise people to always use |
I can't reproduce this behavior on bleeding edge. I created a directory structure containing the following:
where
I then ran When I run the command-line analyzer on Could you enable the instrumentation log file, load a project like this into Dart Code, and then send me the log file? (Private e-mail is fine if you don't want to attach it.) That will let me see whether there's a mismatch between client and server. |
Yeah, I figured this most generally work or there would be loads of issues!
Yep, attached is the log for the zip file I attached at the top. I'm puzzled about why it only seems to happen in Dart Code; it doesn't seem like Dart Code is doing much that could influence this, but the original reporter also tested in Atom and it didn't happen! |
Yeah, I'm puzzled too. Unfortunately, the instrumentation log doesn't show anything that gives me any clues. There are only two requests, both perfectly reasonable, and there's nothing else that Dart Code needed to do. It might be interesting to get a similar log from Atom for comparison, but I honestly don't expect to see anything different. Just for completeness... Do you and the user both have a Do either you, or the user, have any files or directories in either |
Yep; it was in the zip file up top, but here's the contents:
I don't believe so, but just to be sure I moved the
Oh crap, I just realised when looking at the files that I totally neglected to mention that strong-mode is enabled via analyzer:
strong-mode: true It was in the zip, but I didn't mention it in the text so if you tried building your own repro you probably missed this. I'm not sure how to enable logging in Atom; but if you think the log would be useful to compare, I'm happy to install it and try and figure it out. Since I haven't repro'd it myself I can't say for sure the OP didn't do something differently and maybe it can be repro'd there; so the "only happening in Dart Code" thing might be a red herring. |
I enabled strong-mode, but as I expected there was no difference. |
Could it be OS-related? I don't have easy access to a non-Windows machine to test, though maybe you have access to a Windows one? Using the zip file I attached is probably easiest in case I described anything else incorrectly; just opening that folder in Dart Code immediately triggers the error. If there's anything else you can think of that I can do to help debug, let me know! |
I opened the same repro folder on both my PC and Mac, both using 1.24.2 SDK. The PC reports this error and the Mac does not. So I wonder whether there's some code that considers both the package import and the relative path as the same file that isn't working correctly on Windows (maybe because of path separators?). |
If it is a Windows specific issue that would explain why I couldn't reproduce it on my Mac.
That sounds sort of plausible, but I'm not sure where that would happen. Analyzer resolves URIs against URIs and then uses a platform-aware algorithm to convert the resulting URI to a file path. If there isn't something interesting about this case, I would have expected a lot more reports of problems from Windows users. |
I thought that too. Do any of you have access to debug this on a Windows machine? I don't have the code running on mine currently, but it probably wouldn't be hard to sort out if someone could give me some pointers on how to debug, I could see if I can get anywhere. |
Unfortunately, no. |
@bwilkerson That was a pretty old comment you replied to :) I believe this issue is fixed along with the other similar issues I sent a PR for. |
Yes :-) but the info about our lack of access to a Windows machine isn't likely to change soon. |
I don't think it's a big issue for this case, if the PR I sent is good then I think this is resolved. Are there CI builds/test runs on Windows to ensure I didn't totally smeg everything? I don't mind digging into Windows-specific issues where I can; I tend to be quite split across Windows and Mac lately anyway. |
Yes, we have bots that run everything on all three platforms: Linux, Mac, and Windows. But the windows bots are not represented in the subset of try bots, so you won't know you've broken windows until the build fails. |
Good to know, ta! |
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. |
@devoncarew @bwilkerson This seems to be cropping up much more recently. I'm happy to help out if I can - previously I tried to create some Windows tests that failed for the same reasons, but got stuck because the memory file system used in tests is effectively case-sensitive. If anyone has ideas about the best way to fix that, I don't mind having a go. (though I'm still slightly blocked by #32702... have managed to get down to the command that's failing, but not figured out why!) |
I'm too are now affected. You can try it with https://github.com/escamoteur/making_flutter_reactive-/tree/problem_with_analyzer when running the App or running flutter analyze everything is ok but in VS code I shows two errors |
@DanTup, it sounds like the fix was correct was correct, but we saw some test failures associated with it. Can you in-line the test failures, or reference them here? I think we should look at addressing them and re-applying the fix. |
I just found the reason, it's because I used a relative path
if I change that to package it's gone |
@devoncarew We don't have tests to cover this; when we made the original fix we shipped it because everything passed (we subsequently discovered that some Windows tests were being skipped, but even when running them, none of the failures relate to this). I'd like to make some failing tests for this (and for the issues introduced by the "fix" we rolled back), but both of them rely on being able to write tests where the file-system is case-insensitive (which isn't the case for the unit tests) or integration tests where we can ensure the VM and whatever's driving the analysis server are using different cased drive letters. I'll add to the list to discuss tomorrow and maybe we can come up with a plan. @escamoteur Mixing relative and |
I don't think there would be a problem with making |
I thought that'd be an easy change to make, but I think it was full of Also, to confuse things, new Macs seem to also be case-insensitive (though don't hit this issue generally because there isn't a random part of the path being exposed with differing casing in different places) so I'm not sure how complicated this will get (for ex. if I have both a case-sensitive and case-insensitive filesystem on my Mac and run Dart programs from both, should they honour the sensitivity for each drive? Could be a can of worms!) |
One of the constructors for
Hm. I'm running 10.13.3, and at least in a console window that appears to be true. All of our tests are passing, though. Raises the interesting question of whether case insensitivity is really the issue here.
I would avoid that if at all possible. |
I think it's just luck that on Mac all the paths that come from the system are consistent, but on Windows the drive letters are not. Does make me wonder whether we can repro the issue by faking the casing of the path in setAnalysisRoots to something different to what the underlying folders were cased though. I'll have a quick play tomorrow and see where I get. |
Ok, I repro'd on a Mac really easily (not sure why I hadn't tried this sooner!).. Took the zip file from the very top of this post, and I made this in Dart Code where we send analysis roots:
This results in the path being used by the editor to not match the one that the analysis server is using for {
"resource": "/USERS/DANTUP/DESKTOP/REPRO/lib/a.dart",
"owner": "dart",
"code": "strong_mode_invalid_method_override",
"severity": 8,
"message": "Invalid override. The type of 'Mesh.render' ('(Renderer) → void') isn't a subtype of 'Renderable.render' ('(Renderer) → void').",
"source": "dart",
"startLineNumber": 11,
"startColumn": 5,
"endLineNumber": 11,
"endColumn": 44
} So, if we have integration tests that use the real file system (and not the in-memory one), a failing test should be pretty easy. If not, we might still need to change the in-memory file system to be case-insensitive to do that. Fixing things is its own can of worms. What casing of paths do we send back to the client - the case they sent to server or the case we think it is? And how do we handle mixed-case-sensitivity (you can import a Dart file from another drive)? We could try a partial fix similar to what we did last time, which is to just normalise Windows drive letters in one direction everywhere and inform clients they have to deal with that - that all drive letters out of the server will be upper(/lower)case regardless of what they sent (or even, that they must always send uppercase). I'm now wondering if me normalising drive letters to uppercase in Dart Code would actually fix this (well, at least for the Windows users hitting it casually) - VS Code currently normalises to lowercase (for the editor, sadly it's uppercase for the debugger!) if the SDK is consistently getting uppercase drive letters (it's hard to say without knowing where it gets that from). If this turns out to be a huge job, I can give it a go - I think that in all cases where VS Code is normalising my drive letter I'll be accessing the |
I don't know how risky this is (for ex. if there are any people currently getting lowercase drive letters in the analysis server, this will break things for them) but I've put the changes on a branch behind a flag and given a custom build to @escamoteur. If all goes well, this may be a quicker way to solve the users issues without having to divert a load of effort here. |
Slight update on this... I shipped a flag in the last version of Dart Code that allows users to force the drive letters to uppercase. It fixes some of the issues, but others remain relating to casing of other parts of the parts. I found I can easily repro this on my Mac without needing to make changes to Dart Code (it's possible it'll repro in IntelliJ in the same way). Open the original repro from the very top of this Issue, but provide an incorrectly cased path to Code, for example, I extracted it to a folder named
This causes Code to think the folder is cased as
I'm going to see if I can detect when this happens (if I can get the "real" path of the workspace at startup, I can compare it to what's opened) and show a warning. |
Should help with isses like #798 and dart-lang/sdk#28895.
Copying this from Dart-Code/Dart-Code#261 as I don't think it's specific to Dart Code (however, I can't explain why Atom or DartAnalyzer wouldn't show the same issue).
Here is a smaller repro than attached to the Dart Code issue, it's basically:
lib/a.dart
lib/b.dart
There's also a pubspec with just a name and I've run
pub get
.The error reported is:
There's only one
Renderer
class so it seems like these should be the same and the error is incorrect, however the files reference each other, I'm not sure if that's supported?The log from the AS server is this:
The text was updated successfully, but these errors were encountered: