Skip to content
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

Detect incorrect module declarations #1220

Merged
merged 1 commit into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3235,8 +3235,12 @@ let PostParseModuleImpl (_i,defaultNamespace,isLastCompiland,filename,impl) =

| ParsedImplFileFragment.AnonModule (defs,m)->
let isLast, isExe = isLastCompiland
if not (isLast && isExe ) && not (doNotRequireNamespaceOrModuleSuffixes |> List.exists (Filename.checkSuffix (String.lowercase filename))) then
errorR(Error(FSComp.SR.buildMultiFileRequiresNamespaceOrModule(),trimRangeToLine m))
let lower = String.lowercase filename
if not (isLast && isExe) && not (doNotRequireNamespaceOrModuleSuffixes |> List.exists (Filename.checkSuffix lower)) then
match defs with
| SynModuleDecl.NestedModule(_) :: _ -> errorR(Error(FSComp.SR.noEqualSignAfterModule(),trimRangeToLine m))
| _ -> errorR(Error(FSComp.SR.buildMultiFileRequiresNamespaceOrModule(),trimRangeToLine m))

let modname = ComputeAnonModuleName (nonNil defs) defaultNamespace filename (trimRangeToLine m)
SynModuleOrNamespace(modname,true,defs,PreXmlDoc.Empty,[],None,m)

Expand All @@ -3259,8 +3263,12 @@ let PostParseModuleSpec (_i,defaultNamespace,isLastCompiland,filename,intf) =

| ParsedSigFileFragment.AnonModule (defs,m) ->
let isLast, isExe = isLastCompiland
if not (isLast && isExe) && not (doNotRequireNamespaceOrModuleSuffixes |> List.exists (Filename.checkSuffix (String.lowercase filename))) then
errorR(Error(FSComp.SR.buildMultiFileRequiresNamespaceOrModule(),m))
let lower = String.lowercase filename
if not (isLast && isExe) && not (doNotRequireNamespaceOrModuleSuffixes |> List.exists (Filename.checkSuffix lower)) then
match defs with
| SynModuleSigDecl.NestedModule(_) :: _ -> errorR(Error(FSComp.SR.noEqualSignAfterModule(),m))
| _ -> errorR(Error(FSComp.SR.buildMultiFileRequiresNamespaceOrModule(),m))

let modname = ComputeAnonModuleName (nonNil defs) defaultNamespace filename (trimRangeToLine m)
SynModuleOrNamespaceSig(modname,true,defs,PreXmlDoc.Empty,[],None,m)

Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ buildCouldNotReadVersionInfoFromMscorlib,"Could not read version from mscorlib.d
220,buildAssemblyResolutionFailed,"Assembly resolution failure at or near this location"
221,buildImplicitModuleIsNotLegalIdentifier,"The declarations in this file will be placed in an implicit module '%s' based on the file name '%s'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file."
222,buildMultiFileRequiresNamespaceOrModule,"Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'. Only the last source file of an application may omit such a declaration."
222,noEqualSignAfterModule,"Files in libraries or multiple-file applications must begin with a namespace or module declaration. When using a module declaration at the start of a file the '=' sign is not allowed. If this is a top-level module, consider removing the = to resolve this error."
223,buildMultipleToplevelModules,"This file contains multiple declarations of the form 'module SomeNamespace.SomeModule'. Only one declaration of this form is permitted in a file. Change your file to use an initial namespace declaration and/or use 'module ModuleName = ...' to define your modules."
224,buildOptionRequiresParameter,"Option requires parameter: %s"
225,buildCouldNotFindSourceFile,"Source file '%s' could not be found"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This testcase will emit a warning even though it contains a module, becase
// it is a nested module and not a 'real' module

//<Expects status="error" span="(7,1)" id="FS0222">Files in libraries or multiple-file applications must begin with a namespace or module declaration, e\.g\. 'namespace SomeNamespace\.SubNamespace' or 'module SomeNamespace\.SomeModule'\. Only the last source file of an application may omit such a declaration\.$</Expects>
//<Expects status="error" span="(7,1)" id="FS0222">Files in libraries or multiple-file applications must begin with a namespace or module declaration. When using a module declaration at the start of a file the '=' sign is not allowed. If this is a top-level module, consider removing the = to resolve this error.</Expects>

module ANestedModule =

Expand Down