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

Fixing #461 - warning with a reference to non existing location in source file #1852

Merged
merged 7 commits into from
Dec 14, 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
6 changes: 4 additions & 2 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3146,12 +3146,14 @@ let ComputeQualifiedNameOfFileFromUniquePath (m, p: string list) = QualifiedName
let QualFileNameOfSpecs filename specs =
match specs with
| [SynModuleOrNamespaceSig(modname,_,true,_,_,_,_,m)] -> QualFileNameOfModuleName m filename modname
| _ -> QualFileNameOfFilename (rangeN filename 1) filename
| [SynModuleOrNamespaceSig(_,_,false,_,_,_,_,m)] -> QualFileNameOfFilename m filename
| _ -> QualFileNameOfFilename (mkRange filename pos0 pos0) filename

let QualFileNameOfImpls filename specs =
match specs with
| [SynModuleOrNamespace(modname,_,true,_,_,_,_,m)] -> QualFileNameOfModuleName m filename modname
| _ -> QualFileNameOfFilename (rangeN filename 1) filename
| [SynModuleOrNamespace(_,_,false,_,_,_,_,m)] -> QualFileNameOfFilename m filename
| _ -> QualFileNameOfFilename (mkRange filename pos0 pos0) filename

let PrepandPathToQualFileName x (QualifiedNameOfFile(q)) = ComputeQualifiedNameOfFileFromUniquePath (q.idRange,pathOfLid x@[q.idText])
let PrepandPathToImpl x (SynModuleOrNamespace(p,b,c,d,e,f,g,h)) = SynModuleOrNamespace(x@p,b,c,d,e,f,g,h)
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/range.fs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ let rangeContainsPos (m1:range) p =
let rangeBeforePos (m1:range) p =
posGeq p m1.End

let rangeN filename line = mkRange filename (mkPos line 0) (mkPos line 80)
let rangeN filename line = mkRange filename (mkPos line 0) (mkPos line 0)
let pos0 = mkPos 1 0
let range0 = rangeN "unknown" 1
let rangeStartup = rangeN "startup" 1
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/typecheck/sigs/neg10.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ neg10.fs(456,24,456,25): typecheck error FS0001: The type 'C' does not support a

neg10.fs(457,26,457,27): typecheck error FS0001: The type 'C' does not support a conversion to the type 'decimal'

neg10.fsi(1,1,1,81): typecheck error FS0240: The signature file 'Neg10' does not have a corresponding implementation file. If an implementation file exists then check the 'module' and 'namespace' declarations in the signature and implementation files match.
neg10.fsi(1,1,1,1): typecheck error FS0240: The signature file 'Neg10' does not have a corresponding implementation file. If an implementation file exists then check the 'module' and 'namespace' declarations in the signature and implementation files match.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #Regression #Conformance #SignatureFiles
// Test you get an error if you specify an .fsi file but not the corresponding .fs file.

//<Expects id="FS0240" status="error" span="(1,1)">The signature file 'E_MissingSourceFile01' does not have a corresponding implementation file\. If an implementation file exists then check the 'module' and 'namespace' declarations in the signature and implementation files match</Expects>
//<Expects id="FS0240" status="error" span="(8,1)">The signature file 'E_MissingSourceFile01' does not have a corresponding implementation file\. If an implementation file exists then check the 'module' and 'namespace' declarations in the signature and implementation files match</Expects>

namespace FSharp.Testing.MissingSourceFile01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Empty program entry point warning
// Lack of entry point produces warning with correct source location when compiled to *.exe
// when multiple namespaces with multiple modules declared in source file
//<Expects id="FS0988" span="(1,81-1,81)" status="warning">Main module of program is empty: nothing will happen when it is run</Expects>
//<Expects id="FS0988" span="(1,1-1,1)" status="warning">Main module of program is empty: nothing will happen when it is run</Expects>

#light
namespace MyNamespace1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Empty program entry point warning
// Lack of entry point produces warning with correct source location when compiled to *.exe
// when single module declared inside namespace
//<Expects id="FS0988" span="(1,81-1,81)" status="warning">Main module of program is empty: nothing will happen when it is run</Expects>
//<Expects id="FS0988" span="(11,24-11,24)" status="warning">Main module of program is empty: nothing will happen when it is run</Expects>

#light
namespace MyNamespace1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Empty program entry point warning
// Lack of entry point produces warning with correct source location when compiled to *.exe
// when source file declares type inside namespace
//<Expects id="FS0988" span="(1,81-1,81)" status="warning">Main module of program is empty: nothing will happen when it is run</Expects>
//<Expects id="FS0988" span="(10,18-10,18)" status="warning">Main module of program is empty: nothing will happen when it is run</Expects>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed we shouldn't report a non-existent location, but we need to report this on some actual source text, not a single character

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it always only used the m.EndRange for the error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I guess a real single character is better than a non-existent single character :)

It would be better to give the error at a more real textual range but that is indeed further work


#light
namespace MyNamespace1
Expand Down
7 changes: 7 additions & 0 deletions tests/fsharpqa/Source/Warnings/FS0988AtEndOfFile.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// #Warnings
//<Expects status="warning" span="(7,24)" id="FS0988">Main module of program is empty: nothing will happen when it is run</Expects>

namespace MyNamespace1

module MyModule1 =
let irrelevant = 10
1 change: 1 addition & 0 deletions tests/fsharpqa/Source/Warnings/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
SOURCE=InvalidRecord.fs # InvalidRecord.fs
SOURCE=CommaInRecCtor.fs # CommaInRecCtor.fs
SOURCE=ValidCommaInRecCtor.fs # ValidCommaInRecCtor.fs
SOURCE=FS0988AtEndOfFile.fs # FS0988AtEndOfFile.fs
SOURCE=WrongArity.fs # WrongArity.fs
SOURCE=AccessOfTypeAbbreviation.fs # AccessOfTypeAbbreviation.fs
SOURCE=AccessOfTypeAbbreviation2.fs # AccessOfTypeAbbreviation2.fs
Expand Down