Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit780b6c4

Browse files
authored
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
1 parent9da66d1 commit780b6c4

File tree

8 files changed

+51
-18
lines changed

8 files changed

+51
-18
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,9 +2001,15 @@ let ResolveFileUsingPaths(paths, m, name) =
20012001
raise(FileNameNotResolved(name, searchMessage, m))
20022002

20032003
letGetWarningNumber(m,s:string)=
2004-
try
2005-
Some(int32 s)
2006-
with err->
2004+
try
2005+
// Okay so ...
2006+
// #pragma strips FS of the #pragma "FS0004" and validates the warning number
2007+
// therefore if we have warning id that starts with a numeric digit we convert it to Some (int32)
2008+
// anything else is ignored None
2009+
if Char.IsDigit(s.[0])then Some(int32 s)
2010+
elif s.StartsWith("FS", StringComparison.Ordinal)=truethen raise(new ArgumentException())
2011+
else None
2012+
with err->
20072013
warning(Error(FSComp.SR.buildInvalidWarningNumber(s), m))
20082014
None
20092015

@@ -5549,4 +5555,3 @@ let TypeCheckClosedInputSet (ctok, checkForErrors, tcConfig, tcImports, tcGlobal
55495555
let(tcEnvAtEndOfLastFile,topAttrs,implFiles),tcState= TypeCheckMultipleInputs(ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, inputs)
55505556
lettcState,declaredImpls= TypeCheckClosedInputSetFinish(implFiles, tcState)
55515557
tcState, topAttrs, declaredImpls, tcEnvAtEndOfLastFile
5552-

‎src/fsharp/CompileOptions.fs‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,31 +551,41 @@ let inputFileFlagsFsc tcConfigB = inputFileFlagsBoth tcConfigB
551551
//---------------------------------
552552

553553
leterrorsAndWarningsFlags(tcConfigB:TcConfigBuilder)=
554+
lettrimFS(s:string)=if s.StartsWith("FS", StringComparison.Ordinal)=truethen s.Substring(2)else s
555+
lettrimFStoInt(s:string)=
556+
try
557+
Some(int32(trimFS s))
558+
with_->
559+
errorR(Error(FSComp.SR.buildArgInvalidInt(s),rangeCmdArgs))
560+
None
554561
[
555562
CompilerOption("warnaserror", tagNone, OptionSwitch(fun switch-> tcConfigB.globalWarnAsError<- switch<> OptionSwitch.Off), None,
556563
Some(FSComp.SR.optsWarnaserrorPM()));
557564

558-
CompilerOption("warnaserror", tagWarnList, OptionIntListSwitch(fun n switch->
565+
CompilerOption("warnaserror", tagWarnList, OptionStringListSwitch(fun n switch->
566+
match trimFStoInt nwith
567+
| Some n->
559568
if switch= OptionSwitch.Offthen
560-
tcConfigB.specificWarnAsError<- ListSet.remove(=) n tcConfigB.specificWarnAsError;
569+
tcConfigB.specificWarnAsError<- ListSet.remove(=) n tcConfigB.specificWarnAsError
561570
tcConfigB.specificWarnAsWarn<- ListSet.insert(=) n tcConfigB.specificWarnAsWarn
562571
else
563-
tcConfigB.specificWarnAsWarn<- ListSet.remove(=) n tcConfigB.specificWarnAsWarn;
564-
tcConfigB.specificWarnAsError<- ListSet.insert(=) n tcConfigB.specificWarnAsError), None,
572+
tcConfigB.specificWarnAsWarn<- ListSet.remove(=) n tcConfigB.specificWarnAsWarn
573+
tcConfigB.specificWarnAsError<- ListSet.insert(=) n tcConfigB.specificWarnAsError
574+
| None->()), None,
565575
Some(FSComp.SR.optsWarnaserror()));
566-
576+
567577
CompilerOption("warn", tagInt, OptionInt(fun n->
568578
tcConfigB.globalWarnLevel<-
569579
if(n>=0&& n<=5)then n
570580
else error(Error(FSComp.SR.optsInvalidWarningLevel(n),rangeCmdArgs))), None,
571581
Some(FSComp.SR.optsWarn()));
572-
573-
CompilerOption("nowarn", tagWarnList, OptionStringList(fun n-> tcConfigB.TurnWarningOff(rangeCmdArgs, n)), None,
574-
Some(FSComp.SR.optsNowarn()));
575582

576-
CompilerOption("warnon", tagWarnList, OptionStringList(fun n-> tcConfigB.TurnWarningOn(rangeCmdArgs,n)), None,
577-
Some(FSComp.SR.optsWarnOn()));
578-
583+
CompilerOption("nowarn", tagWarnList, OptionStringList(fun n-> tcConfigB.TurnWarningOff(rangeCmdArgs, trimFS n)), None,
584+
Some(FSComp.SR.optsNowarn()));
585+
586+
CompilerOption("warnon", tagWarnList, OptionStringList(fun n-> tcConfigB.TurnWarningOn(rangeCmdArgs, trimFS n)), None,
587+
Some(FSComp.SR.optsWarnOn()));
588+
579589
CompilerOption("consolecolors", tagNone, OptionSwitch(fun switch-> enableConsoleColoring<- switch= OptionSwitch.On), None,
580590
Some(FSComp.SR.optsConsoleColors()))
581591
]

‎tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//<Expects status="success">section='- CODE GENERATION - ' ! option=tailcalls kind=OptionSwitch</Expects>
2525
//<Expects status="success">section='- CODE GENERATION - ' ! option=crossoptimize kind=OptionSwitch</Expects>
2626
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionSwitch</Expects>
27-
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionIntListSwitch</Expects>
27+
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionStringListSwitch</Expects>
2828
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warn kind=OptionInt</Expects>
2929
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=nowarn kind=OptionStringList</Expects>
3030
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnon kind=OptionStringList</Expects>

‎tests/fsharpqa/Source/CompilerOptions/fsc/dumpAllCommandLineOptions/dummy.fsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//<Expects status="success">section='- CODE GENERATION - ' ! option=tailcalls kind=OptionSwitch</Expects>
1818
//<Expects status="success">section='- CODE GENERATION - ' ! option=crossoptimize kind=OptionSwitch</Expects>
1919
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionSwitch</Expects>
20-
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionIntListSwitch</Expects>
20+
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnaserror kind=OptionStringListSwitch</Expects>
2121
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warn kind=OptionInt</Expects>
2222
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=nowarn kind=OptionStringList</Expects>
2323
//<Expects status="success">section='- ERRORS AND WARNINGS - ' ! option=warnon kind=OptionStringList</Expects>

‎tests/fsharpqa/Source/CompilerOptions/fsc/warn/env.lst‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ NoMTSOURCE=warn5_level5.fs SCFLAGS="--warn:5 --warnaserror" COMPILE_ONLY=1# w
1010
NoMTSOURCE=warn5_level5w.fs SCFLAGS="--warn:5" COMPILE_ONLY=1# warn5_level5w.fs
1111

1212
SOURCE=invalid_warning_level_6.fs SCFLAGS="--warn:6" # invalid_warning_level_6.fs
13-
SOURCE=nowarn.fs SCFLAGS="--warnaserror" # nowarn.fs
13+
SOURCE=nowarn.fs SCFLAGS="--warnaserror" # nowarn.fs
14+
SOURCE=warn40.fs SCFLAGS="--nowarn:40" # warn40a.fs
15+
SOURCE=warn40.fs SCFLAGS="--nowarn:NU0000;FS40;NU0001" # warn40b.fs
16+
SOURCE=warn40.fs SCFLAGS="--nowarn:FS0040" # warn40c.fs
1417

1518
SOURCE=nowarn_with_warnaserror01.fs SCFLAGS="--warnaserror --warn:4" COMPILE_ONLY=1# nowarn_with_warnaserror01.fs
1619
SOURCE=nowarn_with_warnaserror02.fs SCFLAGS="--warnaserror --warn:4" COMPILE_ONLY=1# nowarn_with_warnaserror02.fs
1720
SOURCE=nowarn_with_warnaserror03.fs SCFLAGS="--warnaserror --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror03.fs
21+
SOURCE=nowarn_with_warnaserror01.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1# nowarn_with_warnaserror01a.fs
22+
SOURCE=nowarn_with_warnaserror02.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1# nowarn_with_warnaserror02a.fs
23+
SOURCE=nowarn_with_warnaserror03.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1 # nowarn_with_warnaserror03a.fs
24+
SOURCE=nowarn_with_warnaserror01.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1# nowarn_with_warnaserror01b.fs
25+
SOURCE=nowarn_with_warnaserror02.fs SCFLAGS="--warnaserror:FS0040 --warn:4" COMPILE_ONLY=1# nowarn_with_warnaserror02b.fs
26+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This causes a warning 40
2+
[<EntryPoint>]
3+
letmain argv=
4+
let recx=lazy(x.Value)
5+
0// return an integer exit code

‎tests/fsharpqa/Source/CompilerOptions/fsc/warnaserror/env.lst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SOURCE=t1.fs SCFLAGS="--warnaserror+ --warnaserror-:FS25,FS26,FS988# t1a.fs enabled, ex with all warnings, list with >1 element
2+
13
SOURCE=t1.fs SCFLAGS="--warnaserror+ --warnaserror-:25,26,988# t1.fs enabled, excl list with all warnings, list with >1 element
24
SOURCE=t2.fs SCFLAGS="--warnaserror+ --warnaserror-:25,26# t2.fs enabled, excl list with some warning, list with >1 element
35
SOURCE=t3.fs SCFLAGS="--warnaserror+ --warnaserror-:25# t3.fs enabled, excl list with one warning, list with 1 element
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
SOURCE=warnon01.fs SCFLAGS="--warnon:1182 --test:ErrorRanges" COMPILE_ONLY=1# warnon01.fs
22
SOURCE=warnon01.fsx SCFLAGS="--warnon:1182" COMPILE_ONLY=1 FSIMODE=PIPE# warnon01.fsx
33

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp