提交 780b6c4a 编写于 作者: K Kevin Ransom (msft) 提交者: GitHub

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

* enable fs as prefix and ignore invalid values for warnings + tests

* Allow #pragma to validate warnings

* do it right

* use ordinal compare

* In both places

* Add fs prefix to warnaserror

* Fixup tests
上级 9da66d14
......@@ -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
......@@ -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
......@@ -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()))
]
......
......@@ -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>
......
......@@ -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>
......
......@@ -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
// This causes a warning 40
[<EntryPoint>]
let main argv =
let rec x = lazy(x.Value)
0 // return an integer exit code
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
......
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册