-
Notifications
You must be signed in to change notification settings - Fork 821
"Open declaration can be removed" - but actually it cannot #3347
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
Why it cannot be removed? |
because then compile errors happen |
it's a false postive |
@forki I guess @vasily-kirichenko is asking for the compiler error or the statement which needs the |
No, I'm asking for the source code of a symbol that makes the open statement needed. |
(I guess it's the exception definition) |
see screenshot |
^^ is the other file |
Thanks. |
Ah, relative opens. They are not supported. Use full ns/module names. |
What do you mean they are not supported? That's proper F# - the tooling should adjust and not my code, right? If there is no way to make it work with relative opens then it should be disabled for relative opens, right? Also not that |
Right :) The problem is that opens are not symbols, they are text from untyped AST. However, if it works properly for |
Sorry, Ctrl+F5 crashes VS immediately on my machine :)) |
Perhaps a code fix to turn relative opens into fully-qualified opens. |
I believe this is an exact duplicate of the older #3306. |
This issue seems to be mitigated. You can still get a lightbulb which will remove it, but |
What is a "relative open"? |
Issue #7111 was just marked as a duplicate of this one. That issue includes a very minimal working example. The consensus here seems to be that the present issue is related to the concept of a "relative open", which is contrasted with a "fully-qualified open". I have only ever heard these terms in this issue. Is there documentation that explains what these terms mean? If not, can someone explain what these terms mean in this issue? Because of my lack of knowledge (both generally of F# and specifically about the answer to those two questions) and the not-so-minimal working example provided in the present issue, I am unable to verify for myself that issue #7111 is a duplicate of this one. |
@bender2k14, a relative open is when you don't fully specify the whole namespace, or the namespace before the module. A fully qualified open is when, in contrast, you do specify the FQN (fully qualified name) in the open statement. open System // fqn
open IO // relative, will raise FS0893, which shows these terms, see below
Here is a valid way: module X =
module Y =
let z = 10
module Z =
open Y // relative open of MyNamespace.X.Y
let a = z // use of X.Y.z, as can be seen, in this case the "unusued open" warning disappears Btw, I agree that the documentation is rather limited, and also doesn't mention the peculiarities in opening namespaces vs opening modules, or nested modules. https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/import-declarations-the-open-keyword.
I have seen several issues of false positives w.r.t. unused opens. Inlined members, type aliases and some more complex namespace + type/module hierarchies, type forwarding and more can all lead to this situation where the suggestion to remove the unused open is invalid. I think it would be good to collect a couple of simple repros so that working on the issue in a PR becomes easier. The code that does this currently is in |
Slight correction, the analyzer itself lives here: https://github.com/dotnet/fsharp/blob/master/src/fsharp/service/ServiceAnalysis.fs#L12 As mentioned earlier in this issue there is a problem related to the data that is being operated on here. It can likely be fiddled with a bit. |
Thanks @abelbraaksma. That is very helpful.
Are there any existing unit tests for this unused open analyzer? If so, I might be able to add tests for the cases that have been reported in this and the linked issues. |
I assume there are, but where exactly I don't know. I haven't played with this part of the tooling yet. |
In this case there are some fairly comprehensive tests here: https://github.com/dotnet/fsharp/blob/master/vsintegration/tests/UnitTests/UnusedOpensTests.fs |
I tried and failed to reproduce the bugs reported in this issue and the two linked issues. Here is the environment I used.
Seems like all these bugs are fixed. I recommend closing this issue.
Thanks @cartermp. I was so excited to contribute something to F# that I confirmed that the 67 unused open tests pass on my machine before confirming that I had a MWE to make into a test. I see there are more open issues in this repo, so I will investigate them now. |
Thanks @bender2k14 - I also failed to reproduce the issue in the latest internal preview build of the F# tools. It could be that something changed since this report was initially filed that influences the lack of repro, but looking at the history of the codebase it doesn't appear to be the case. I'll close this one out. |
Uh oh!
There was an error while loading. Please reload this page.
Repro steps
If you accept then you get compile errors
Expected behavior
Don't show the suggestion
/cc @vasily-kirichenko
The text was updated successfully, but these errors were encountered: