diff --git a/src/fsharp/CompileOps.fs b/src/fsharp/CompileOps.fs index 70666dd6b23..4ff176e17ed 100755 --- a/src/fsharp/CompileOps.fs +++ b/src/fsharp/CompileOps.fs @@ -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) @@ -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) diff --git a/src/fsharp/FSComp.txt b/src/fsharp/FSComp.txt index 04ac2ac620a..28b15426e03 100644 --- a/src/fsharp/FSComp.txt +++ b/src/fsharp/FSComp.txt @@ -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" diff --git a/tests/fsharpqa/Source/Conformance/ImplementationFilesAndSignatureFiles/NamespacesFragmentsAndImplementationFiles/basic/E_NoNamespaceModuleDec02a.fs b/tests/fsharpqa/Source/Conformance/ImplementationFilesAndSignatureFiles/NamespacesFragmentsAndImplementationFiles/basic/E_NoNamespaceModuleDec02a.fs index 780614d5292..cf4a81f9441 100644 --- a/tests/fsharpqa/Source/Conformance/ImplementationFilesAndSignatureFiles/NamespacesFragmentsAndImplementationFiles/basic/E_NoNamespaceModuleDec02a.fs +++ b/tests/fsharpqa/Source/Conformance/ImplementationFilesAndSignatureFiles/NamespacesFragmentsAndImplementationFiles/basic/E_NoNamespaceModuleDec02a.fs @@ -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 -//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\.$ +//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. module ANestedModule =