-
Notifications
You must be signed in to change notification settings - Fork 789
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
Improve error reporting: Detect module declarations that incorrectly end with =
#1214
Comments
=
Good one. So I guess that this is caused by the I'm not sure that the standard guidelines for messages that we've been following that @dsyme has mentioned will work in this case (i.e. "what is the error / why is it occurring / how can you resolve it") because of the nature of the error. Assuming that it's possible to identify this situation, I'd suggest an error along the lines of: -
|
=
=
Suggest
|
That's better, yes. Perhaps just just replace |
TBH I don't understand why we give an error in this case.
Put this in a file called ModuleWithoutNamespace.fs and it doesn't compile. Why? |
I mean it looks like a perfectly valid file. Copy the same code into fsi and it compiles. @dsyme why do we reject that.? |
Isn't it because |
the code is like this: if not (isLast && isExe) && not (Filename.checkSuffix filename ".fsx" )) then So if we are in fsx file we just use the filename as "outer" module. Why can't we do that in fs files? |
That only works for the last file in an exe AFAIK.... I've always wondered if that could be added for all files in a project. |
I would suggest raising a separate issue for that though - it's not about error message but about changing compiler behaviour. |
…end with `=` - fixes dotnet#1214
WIP PR for error message #1220 |
Basically,
We don't allow the second to be interpreted as the first because of the following 1 - In a script or last file, we allow programs like let x = 1 In these cases, the code is places in a module taken from the file name, say 2 - That implies that the following is valid code in a script or last file: module X =
let x = 1
module Y =
let x = 1 This compiles to two nested types 3 - So, in the last file, we also expect this to be valid code:
Further the compilation representation should be predictable and consistent: deleting Y shouldn't change the compilation representation of 4 - Adding a file shouldn't change the compilation representation of existing modules. Hence adding a file after this last file shouldn't change the compilation representation of |
@dsyme |
…end with `=` - fixes dotnet#1214
…end with `=` - fixes dotnet#1214
…end with `=` - fixes dotnet#1214
Depending on whether you have a namespace or not, a module declaration may or may not require an
=
. This caught me out today (it's been a long time since I did any F#); I created a new file and deleted the namespace and got this compile error:As I had some F# code open in my browser that had
module blah =
I copied it and continued to get the same message:In hindsight, the example given in the message doesn't have an
=
so I should've figured it out, but it actually took much googling and finding a comment on this answer that made me realise the issue.I think it might be worthwhile calling this out in the message (or ideally, detecting when there is a module declaration with an
=
that shouldn't be there and giving a specific message). It seems effort is going into improving messages in #1103.The text was updated successfully, but these errors were encountered: