-
Notifications
You must be signed in to change notification settings - Fork 790
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
VS editor shows bogus errors when scripts use multi-hop #r and #load with relative paths #273
Comments
Have you tried adding
to your script? |
@dsyme thanks for the hint which helps. Are you saying it's a workaround or it's the expected way to do it? I believe while it might allow me to work around the issue with I haven't figured a way to encounter error related to Ideally, I would like to try to gather information on the matter, the documentation on msdn is not very detailled: https://msdn.microsoft.com/en-us/library/dd233175.aspx
As there is no details explaining how the location resolution works for both, I would expect the behaviour to be identical; apparently It would be good to explain how those differs or to make them behave identically. I would ideally prefer the least expected surprise with paths always relative to the file which contain the declaration, never from where the compiler/interpreter is invoked or the file including the other is located. |
Yes, I agree this is inconsistent. Using It's hard to make a fix to this since it would definitely be a breaking change. @latkin - you might like to take a look at the difference in behaviour here. Perhaps an MSDN doc fix would help here too? |
Just throwing this out there, and I have given it exactly zero thought so far but, maybe we can add a new directive: #location "blah" or # workingdir "blah" or #projectdir "blah" or something similar and when that is specified relative paths in #load and #r are relative to that. That wouldn't be a breaking change. And it may nail down and make deterministic those relative paths. |
@dsyme isn't this a breaking changes leading to compile error (script won't run at all) as opposed to those happening silently at runtime in case of resolution failure? As far as I understand the scripts relying on Also, the bug fix / test case referenced (LoadScriptResolution01.fsx ) was most probably a breaking change. I understand being very cautious about breaking changes in general (API, libraries) but this seems to be a case where assembly references issues will popup when something really exotic was done in order to work around the issue we are discussing. I might of course overlook other cases in the wild. @KevinRansom what you propose would also work,but would add confusion to a system I assume should be very simple / surprise free (from user perspective, not saying it's easy to implement correctly). If we really want to go this route, allowing Similarly in the appendix regarding TP, it would make sense to expose a way to obtain the file location of code instanciating the TP, right now the library tries to do it's job based on the place of invocation of the compiler, on which we don't have much control, that works well for flat solutions with all files in a single folder but beyond that it's painful. My vote goes for fixing inconsistent behaviour (make it work like Thanks a lot for the workaround and considering the issue. |
Did anyone else try this? I do not repro -- FSI behavior is just as requested: See my session here, showing content and location of all files. Do I have the scenario wrong? The |
I have a repro case, and the work around actually doesn't help 😞 (it's the case I initially hit but I simplified too much) : You only need two files: ./fub/baz/boo/fubbazboo.fsx #load "../../../bar/baz/barbaz.fsx"
printfn "%O" BarBaz.barbaz
printfn "%O" typeof<BarBaz.wmi> ./bar/baz/barbaz.fsx //#I __SOURCE_DIRECTORY__ // you can also uncomment it
#r "System.Management"
#r "../../lib/FSharp.Management.dll"
#r "../../lib/FSharp.Management.WMI.dll"
let barbaz = 2
type wmi = FSharp.Management.WmiProvider<"localhost"> ./lib/ (I put FSharp.Management there) running ./fub/baz/boo/fubbazboo.fsx from various places with fsi lead to C:\tmp>"C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\Fsi.exe" c:\tmp\fub\baz\boo\fubbazboo.fsx
fubbazboo.fsx(3,14): error FS0039: The namespace or module 'BarBaz' is not defined
C:\tmp> Hope this helps. |
Yes, IIRC problems come when you #load a file in another directory that itself contains relative #load, or if you run a script with relative #load from a different location using the command line fsi.exe |
The |
@rojepp: I think #I is only usable from script files, so no won't help. I just mentionned this because I think all path resolution concerns should be addressed with an as global as possible picture, so the behaviour can be consistent across the landscape. @dsyme, @KevinRansom, @latkin:
my understanding is such: #load
#I
#r
crawling behaviourwithout incudes#r "../../../../some/path/to/myassembly.dll"
with incudes and subfolder containing assembliesif #I has a folder containing some/path/to/myassembly.dll: #I "c:/myassemblies"
#r "../../../../some/path/to/myassembly.dll"
with incudes of a folder containing assembliesif #I has myassembly.dll #I "c:/myassemblies"
#r "../../../../some/path/to/myassembly.dll"
Please let me know if those ''ideal assumptions'' are correct, and whether you find out they work correctly or not in current implementations of F# (I initially hit this issue with 3.1, but reproduced with bits shipping in VS2015). I hope I gave enough details explaining how I assume it should work 😃 |
I still do not repro any issue with crawling behavior in FSI. I'm pretty sure your issue is unrelated to relative paths or crawling, and rather due to the fact that the casing of the So if you do Can you check if this fixes your problem? |
@latkin, man, I can't believe I couldn't figure this out, issue with case sensitiveness on non case sensitive file system... So what remains is a bug in VS tooling:
Both in VS and fsc/fsi, many ways to shoot self in the foot with:
my guess is that tools should take physical name of resolved script and issue a warning if there is mismatch, to eventually make things easier for both people using case sensitive file systems and people overlooking that they are changing the namespace by the way they wrote the reference. I think the VS issue (need #I directive) is a higher priority to fix, the work around is not needed from the command line so experience is not consistent. For the casing stuff, compiler should identify potential mismatch and help the user to write a script which will work disregarding filesystem and how the reference is brought, mostly through better warning / diagnostics from both command line tools and IDE integration. This seems less urgent. Can we agree on first bug reproduced? Do we want to move later issue to another ticket to try to clarify the different solutions to help users? Thanks all, and sorry for the agitation. |
Also found that the module name will have a first letter being capitalized whichever way you #load the script, I think this adds opportunity for trip up with all the casing stuff. I know this deals with potential breaking changes, but VS needs to be fixed (should not need #I SOURCE_DIRECTORY) and user need to be guided from both fsc/fsi and VS in a consistent fashion to make the script work disregarding file system case sensistivity. |
Yes, the VS editor does show bogus squiggles here, and that's a bug. Thankfully, things work ok when you send the code to FSI, so it's purely an editor-level issue. I've updated the title of the bug to indicate this reduced scope. Thanks for bringing this up. Request/discussion on redesigning how implicit modules are named belongs at https://fslang.uservoice.com/. I tend to agree that it would be more intuitive if module name came from canonical file name on disk, but making changes to the scheme now would be highly impactful/breaking to many, while benefitting relatively few (IMO). |
@latkin can you try this repro? Basically, the #r in a.fsx is resolved relative to the location of Adding AFAIK this has been a long standing problem since F# 2.0. |
@latkin thanks for the update / requalification, hope it won't be too hard to fix. For discussing the module name mangling thing, I'm wondering if uservoice is the place to start, my concerns are:
Isn't there a repository where RFC are being drafted, I remember seeing this with advanced stuff from @dsyme, I could draft a simple RFC on github exposing the issues, receive some community feedback, then once it's ready submit it to uservoice. Such RFC will:
I'd be happy with just warnings, I don't want others to spend time like I did because something surprising is happening behind the scene. Beside all that which will eventually be great, maybe I can have a couple of minute feedback on those things:
|
@latkin would you agree to remove the |
@dsyme I do repro with your example. However it works if you change from @smoothdeveloper yes, I've added the bug tag. This discussion has ballooned to encompass a variety of feature requests and bugs. Let's please use this issue to just cover the bug as stated in the title - VS tooling for F# scripts is not handling relative paths properly. Per @dsyme's example, seems there is a related (but unique) bug in FSI.exe where non-relative paths are processed with incorrect logic. I've opened #293 to track this. Everything else is feature requests or design change requests and will not be considered here. Those belong on UserVoice. You are free to write up richly-formatted Gist or other doc and link that from UserVoice. |
…f declaring source file fixes dotnet#273 fixes dotnet#293
This should work, this limit scripting to having everything in the same directory, or other convoluted restriction (everything at same nesting level) which is not manageable.
I believe when a relative path is used in a script or source file, in the context of
#r
or#load
fsc or fsi should never assume it's current directory, nor the top level file invoked nor anything like this, it should resolve from the path of the file containing the reference.While I'd like the focus to be on what I describe above, I want to mention two things related to path resolution:
fsprojects/FSharp.Data.SqlClient#112 (comment)
I believe type provider should have a way to get location of file being compiled (even if it applies only when compiling from files), this would give the implementor a way to solve the strange behaviour we see depending where compiler is invoked.
I never get those issues with vb.net or c# project files, this somehow doesn't fail the build but clutters the output pane with misleading information.
The text was updated successfully, but these errors were encountered: