diff --git a/src/fsharp/CompileOps.fs b/src/fsharp/CompileOps.fs index 45d6e3e78c5..293ae17cbf4 100644 --- a/src/fsharp/CompileOps.fs +++ b/src/fsharp/CompileOps.fs @@ -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 - diff --git a/src/fsharp/CompileOptions.fs b/src/fsharp/CompileOptions.fs index 892914d0391..40928c1cb03 100644 --- a/src/fsharp/CompileOptions.fs +++ b/src/fsharp/CompileOptions.fs @@ -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())) ] diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fs b/tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fs index 0adca947bc3..65d7f3ba86d 100644 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fs +++ b/tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fs @@ -24,7 +24,7 @@ //section='- CODE GENERATION - ' ! option=tailcalls kind=OptionSwitch //section='- CODE GENERATION - ' ! option=crossoptimize kind=OptionSwitch //section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionSwitch -//section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionIntListSwitch +//section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionStringListSwitch //section='- ERRORS AND WARNINGS - ' ! option=warn kind=OptionInt //section='- ERRORS AND WARNINGS - ' ! option=nowarn kind=OptionStringList //section='- ERRORS AND WARNINGS - ' ! option=warnon kind=OptionStringList diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fsx b/tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fsx index c112b83d0d1..aa84cfe70f6 100644 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fsx +++ b/tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fsx @@ -17,7 +17,7 @@ //section='- CODE GENERATION - ' ! option=tailcalls kind=OptionSwitch //section='- CODE GENERATION - ' ! option=crossoptimize kind=OptionSwitch //section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionSwitch -//section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionIntListSwitch +//section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionStringListSwitch //section='- ERRORS AND WARNINGS - ' ! option=warn kind=OptionInt //section='- ERRORS AND WARNINGS - ' ! option=nowarn kind=OptionStringList //section='- ERRORS AND WARNINGS - ' ! option=warnon kind=OptionStringList diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/warn/env.lst b/tests/fsharpqa/Source/CompilerOptions/fsc/warn/env.lst index 38ef7217a0b..7c71fc18546 100644 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/warn/env.lst +++ b/tests/fsharpqa/Source/CompilerOptions/fsc/warn/env.lst @@ -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 + diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/warn/warn40.fs b/tests/fsharpqa/Source/CompilerOptions/fsc/warn/warn40.fs new file mode 100644 index 00000000000..c9d56fe2004 --- /dev/null +++ b/tests/fsharpqa/Source/CompilerOptions/fsc/warn/warn40.fs @@ -0,0 +1,5 @@ +// This causes a warning 40 +[] +let main argv = + let rec x = lazy(x.Value) + 0 // return an integer exit code diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/warnaserror/env.lst b/tests/fsharpqa/Source/CompilerOptions/fsc/warnaserror/env.lst index f4f1003891a..fa1ebe0260c 100644 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/warnaserror/env.lst +++ b/tests/fsharpqa/Source/CompilerOptions/fsc/warnaserror/env.lst @@ -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 diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/warnon/env.lst b/tests/fsharpqa/Source/CompilerOptions/fsc/warnon/env.lst index 79000e59bec..b570c0a1a62 100644 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/warnon/env.lst +++ b/tests/fsharpqa/Source/CompilerOptions/fsc/warnon/env.lst @@ -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