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

Enable FS as prefix and ignore invalid values for warnings #3631

Merged
merged 7 commits into from
Sep 27, 2017
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
13 changes: 9 additions & 4 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,9 +2001,15 @@ let ResolveFileUsingPaths(paths, m, name) =
raise (FileNameNotResolved(name, searchMessage, m))

let GetWarningNumber(m, s:string) =
try
Some (int32 s)
with err ->
try
// Okay so ...
// #pragma strips FS of the #pragma "FS0004" and validates the warning number
// therefore if we have warning id that starts with a numeric digit we convert it to Some (int32)
// anything else is ignored None
if Char.IsDigit(s.[0]) then Some (int32 s)
elif s.StartsWith("FS", StringComparison.Ordinal) = true then raise (new ArgumentException())
else None
with err ->
warning(Error(FSComp.SR.buildInvalidWarningNumber(s), m))
None

Expand Down Expand Up @@ -5549,4 +5555,3 @@ let TypeCheckClosedInputSet (ctok, checkForErrors, tcConfig, tcImports, tcGlobal
let (tcEnvAtEndOfLastFile, topAttrs, implFiles), tcState = TypeCheckMultipleInputs (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, inputs)
let tcState, declaredImpls = TypeCheckClosedInputSetFinish (implFiles, tcState)
tcState, topAttrs, declaredImpls, tcEnvAtEndOfLastFile

32 changes: 21 additions & 11 deletions src/fsharp/CompileOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -551,31 +551,41 @@ let inputFileFlagsFsc tcConfigB = inputFileFlagsBoth tcConfigB
//---------------------------------

let errorsAndWarningsFlags (tcConfigB : TcConfigBuilder) =
let trimFS (s:string) = if s.StartsWith("FS", StringComparison.Ordinal) = true then s.Substring(2) else s
let trimFStoInt (s:string) =
try
Some (int32 (trimFS s))
with _ ->
errorR(Error(FSComp.SR.buildArgInvalidInt(s),rangeCmdArgs))
None
[
CompilerOption("warnaserror", tagNone, OptionSwitch(fun switch -> tcConfigB.globalWarnAsError <- switch <> OptionSwitch.Off), None,
Some (FSComp.SR.optsWarnaserrorPM()));

CompilerOption("warnaserror", tagWarnList, OptionIntListSwitch (fun n switch ->
CompilerOption("warnaserror", tagWarnList, OptionStringListSwitch (fun n switch ->
match trimFStoInt n with
| Some n ->
if switch = OptionSwitch.Off then
tcConfigB.specificWarnAsError <- ListSet.remove (=) n tcConfigB.specificWarnAsError ;
tcConfigB.specificWarnAsError <- ListSet.remove (=) n tcConfigB.specificWarnAsError
tcConfigB.specificWarnAsWarn <- ListSet.insert (=) n tcConfigB.specificWarnAsWarn
else
tcConfigB.specificWarnAsWarn <- ListSet.remove (=) n tcConfigB.specificWarnAsWarn ;
tcConfigB.specificWarnAsError <- ListSet.insert (=) n tcConfigB.specificWarnAsError), None,
tcConfigB.specificWarnAsWarn <- ListSet.remove (=) n tcConfigB.specificWarnAsWarn
tcConfigB.specificWarnAsError <- ListSet.insert (=) n tcConfigB.specificWarnAsError
| None -> () ), None,
Some (FSComp.SR.optsWarnaserror()));

CompilerOption("warn", tagInt, OptionInt (fun n ->
tcConfigB.globalWarnLevel <-
if (n >= 0 && n <= 5) then n
else error(Error(FSComp.SR.optsInvalidWarningLevel(n),rangeCmdArgs))), None,
Some (FSComp.SR.optsWarn()));

CompilerOption("nowarn", tagWarnList, OptionStringList (fun n -> tcConfigB.TurnWarningOff(rangeCmdArgs, n)), None,
Some (FSComp.SR.optsNowarn()));

CompilerOption("warnon", tagWarnList, OptionStringList (fun n -> tcConfigB.TurnWarningOn(rangeCmdArgs,n)), None,
Some(FSComp.SR.optsWarnOn()));

CompilerOption("nowarn", tagWarnList, OptionStringList (fun n -> tcConfigB.TurnWarningOff(rangeCmdArgs, trimFS n)), None,
Some (FSComp.SR.optsNowarn()));

CompilerOption("warnon", tagWarnList, OptionStringList (fun n -> tcConfigB.TurnWarningOn(rangeCmdArgs, trimFS n)), None,
Some(FSComp.SR.optsWarnOn()));

CompilerOption("consolecolors", tagNone, OptionSwitch (fun switch -> enableConsoleColoring <- switch = OptionSwitch.On), None,
Some (FSComp.SR.optsConsoleColors()))
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//<Expects status="success">section='- CODE GENERATION - ' ! option=tailcalls kind=OptionSwitch</Expects>
//<Expects status="success">section='- CODE GENERATION - ' ! option=crossoptimize kind=OptionSwitch</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionSwitch</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionIntListSwitch</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionStringListSwitch</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warn kind=OptionInt</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=nowarn kind=OptionStringList</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnon kind=OptionStringList</Expects>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//<Expects status="success">section='- CODE GENERATION - ' ! option=tailcalls kind=OptionSwitch</Expects>
//<Expects status="success">section='- CODE GENERATION - ' ! option=crossoptimize kind=OptionSwitch</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionSwitch</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionIntListSwitch</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionStringListSwitch</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warn kind=OptionInt</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=nowarn kind=OptionStringList</Expects>
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnon kind=OptionStringList</Expects>
Expand Down
11 changes: 10 additions & 1 deletion tests/fsharpqa/Source/CompilerOptions/fsc/warn/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ NoMT SOURCE=warn5_level5.fs SCFLAGS="--warn:5 --warnaserror" COMPILE_ONLY=1 # w
NoMT SOURCE=warn5_level5w.fs SCFLAGS="--warn:5" COMPILE_ONLY=1 # warn5_level5w.fs

SOURCE=invalid_warning_level_6.fs SCFLAGS="--warn:6" # invalid_warning_level_6.fs
SOURCE=nowarn.fs SCFLAGS="--warnaserror" # nowarn.fs
SOURCE=nowarn.fs SCFLAGS="--warnaserror" # nowarn.fs
SOURCE=warn40.fs SCFLAGS="--nowarn:40" # warn40a.fs
SOURCE=warn40.fs SCFLAGS="--nowarn:NU0000;FS40;NU0001" # warn40b.fs
SOURCE=warn40.fs SCFLAGS="--nowarn:FS0040" # warn40c.fs

SOURCE=nowarn_with_warnaserror01.fs SCFLAGS="--warnaserror --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror01.fs
SOURCE=nowarn_with_warnaserror02.fs SCFLAGS="--warnaserror --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror02.fs
SOURCE=nowarn_with_warnaserror03.fs SCFLAGS="--warnaserror --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror03.fs
SOURCE=nowarn_with_warnaserror01.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror01a.fs
SOURCE=nowarn_with_warnaserror02.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror02a.fs
SOURCE=nowarn_with_warnaserror03.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror03a.fs
SOURCE=nowarn_with_warnaserror01.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror01b.fs
SOURCE=nowarn_with_warnaserror02.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror02b.fs

5 changes: 5 additions & 0 deletions tests/fsharpqa/Source/CompilerOptions/fsc/warn/warn40.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This causes a warning 40
[<EntryPoint>]
let main argv =
let rec x = lazy(x.Value)
0 // return an integer exit code
2 changes: 2 additions & 0 deletions tests/fsharpqa/Source/CompilerOptions/fsc/warnaserror/env.lst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SOURCE=t1.fs SCFLAGS="--warnaserror+ --warnaserror-:FS25,FS26,FS988 # t1a.fs enabled, ex with all warnings, list with >1 element

SOURCE=t1.fs SCFLAGS="--warnaserror+ --warnaserror-:25,26,988 # t1.fs enabled, excl list with all warnings, list with >1 element
SOURCE=t2.fs SCFLAGS="--warnaserror+ --warnaserror-:25,26 # t2.fs enabled, excl list with some warning, list with >1 element
SOURCE=t3.fs SCFLAGS="--warnaserror+ --warnaserror-:25 # t3.fs enabled, excl list with one warning, list with 1 element
Expand Down
2 changes: 2 additions & 0 deletions tests/fsharpqa/Source/CompilerOptions/fsc/warnon/env.lst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SOURCE=warnon01.fs SCFLAGS="--warnon:1182 --test:ErrorRanges" COMPILE_ONLY=1 # warnon01.fs
SOURCE=warnon01.fsx SCFLAGS="--warnon:1182" COMPILE_ONLY=1 FSIMODE=PIPE # warnon01.fsx

SOURCE=warnon01.fs SCFLAGS="--warnon:NU0001;FS1182;NU0001 --test:ErrorRanges" COMPILE_ONLY=1 # warnon01a.fs
SOURCE=warnon01.fsx SCFLAGS="--warnon:FS1182" COMPILE_ONLY=1 FSIMODE=PIPE # warnon01a.fsx