Skip to content

Commit 64f4d33

Browse files
committed
fix the checkFile bug
1 parent 27599c0 commit 64f4d33

30 files changed

+150
-21
lines changed

buildtools/fsyacc/fsyaccdriver.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ let writeSpecToFile (generatorState: GeneratorState) (spec: ParserSpec) (compile
199199
writer.WriteLineInterface "module %s" s;
200200

201201
writer.WriteLine "#nowarn \"64\";; // turn off warnings that type variables used in production annotations are instantiated to concrete type";
202+
writer.WriteLine "#nowarn \"1182\" // the generated code often has unused variable 'parseState'"
203+
writer.WriteLine "#nowarn \"3261\" // the generated code would need to properly annotate nulls, e.g. changing System.Object to `obj|null`";
202204

203205
for s in generatorState.opens do
204206
writer.WriteLine "open %s" s;

docs/release-notes/.FSharp.Compiler.Service/9.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Fixed
22

3+
* Fix a bug in the interaction between ``#line` and `#nowarn` directives ([PR #17649](https://github.com/dotnet/fsharp/pull/17649))
34
* Fix wrong TailCall warning ([Issue #17604](https://github.com/dotnet/fsharp/issues/17604), [PR #17637](https://github.com/dotnet/fsharp/pull/17637))
45
* Compiler hangs when compiling inline recursive invocation ([Issue #17376](https://github.com/dotnet/fsharp/issues/17376), [PR #17394](https://github.com/dotnet/fsharp/pull/17394))
56
* Fix reporting IsFromComputationExpression only for CE builder type constructors and let bindings. ([PR #17375](https://github.com/dotnet/fsharp/pull/17375))

docs/release-notes/.Language/preview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Enforce AttributeTargets on union case declarations. ([PR #16764](https://github.com/dotnet/fsharp/pull/16764))
2222
* Enforce AttributeTargets on implicit constructors. ([PR #16845](https://github.com/dotnet/fsharp/pull/16845/))
2323
* Enforce AttributeTargets on structs and classes ([PR #16790](https://github.com/dotnet/fsharp/pull/16790))
24+
* Ensure consistent interaction between ``#line` and `#nowarn` directives ([PR #17649](https://github.com/dotnet/fsharp/pull/17649))
2425

2526
### Changed
2627

src/Compiler/AbstractIL/ilpars.fsy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
%{
44

5+
#nowarn "64" // turn off warnings that type variables used in production annotations are instantiated to concrete type
56
#nowarn "1182" // the generated code often has unused variable "parseState"
67
#nowarn "3261" // the generated code would need to properly annotate nulls, e.g. changing System.Object to `obj|null`
78

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ open FSharp.Compiler.ConstraintSolver
2424
open FSharp.Compiler.DiagnosticMessage
2525
open FSharp.Compiler.Diagnostics
2626
open FSharp.Compiler.DiagnosticsLogger
27+
open FSharp.Compiler.Features
2728
open FSharp.Compiler.Infos
2829
open FSharp.Compiler.IO
2930
open FSharp.Compiler.Lexhelp
@@ -2299,17 +2300,12 @@ type PhasedDiagnostic with
22992300
// Scoped #nowarn pragmas
23002301

23012302
/// Build an DiagnosticsLogger that delegates to another DiagnosticsLogger but filters warnings turned off by the given pragma declarations
2302-
//
2303-
// NOTE: we allow a flag to turn of strict file checking. This is because file names sometimes don't match due to use of
2304-
// #line directives, e.g. for pars.fs/pars.fsy. In this case we just test by line number - in most cases this is sufficient
2305-
// because we install a filtering error handler on a file-by-file basis for parsing and type-checking.
2306-
// However this is indicative of a more systematic problem where source-line
2307-
// sensitive operations (lexfilter and warning filtering) do not always
2308-
// interact well with #line directives.
23092303
type DiagnosticsLoggerFilteringByScopedPragmas
2310-
(checkFile, scopedPragmas, diagnosticOptions: FSharpDiagnosticOptions, diagnosticsLogger: DiagnosticsLogger) =
2304+
(langVersion: LanguageVersion, scopedPragmas, diagnosticOptions: FSharpDiagnosticOptions, diagnosticsLogger: DiagnosticsLogger) =
23112305
inherit DiagnosticsLogger("DiagnosticsLoggerFilteringByScopedPragmas")
23122306

2307+
let bugFixed = langVersion.SupportsFeature LanguageFeature.CheckFileBugFixed
2308+
23132309
let mutable realErrorPresent = false
23142310

23152311
override _.DiagnosticSink(diagnostic: PhasedDiagnostic, severity) =
@@ -2323,12 +2319,10 @@ type DiagnosticsLoggerFilteringByScopedPragmas
23232319
match diagnostic.Range with
23242320
| Some m ->
23252321
scopedPragmas
2326-
|> List.exists (fun pragma ->
2327-
let (ScopedPragma.WarningOff(pragmaRange, warningNumFromPragma)) = pragma
2328-
2322+
|> List.exists (fun (ScopedPragma.WarningOff(pragmaRange, warningNumFromPragma)) ->
23292323
warningNum = warningNumFromPragma
2330-
&& (not checkFile || m.FileIndex = pragmaRange.FileIndex)
2331-
&& posGeq m.Start pragmaRange.Start)
2324+
&& (not bugFixed
2325+
|| m.FileIndex = pragmaRange.FileIndex && posGeq m.Start pragmaRange.Start))
23322326
|> not
23332327
| None -> true
23342328

@@ -2344,5 +2338,5 @@ type DiagnosticsLoggerFilteringByScopedPragmas
23442338

23452339
override _.CheckForRealErrorsIgnoringWarnings = realErrorPresent
23462340

2347-
let GetDiagnosticsLoggerFilteringByScopedPragmas (checkFile, scopedPragmas, diagnosticOptions, diagnosticsLogger) =
2348-
DiagnosticsLoggerFilteringByScopedPragmas(checkFile, scopedPragmas, diagnosticOptions, diagnosticsLogger) :> DiagnosticsLogger
2341+
let GetDiagnosticsLoggerFilteringByScopedPragmas (langVersion, scopedPragmas, diagnosticOptions, diagnosticsLogger) =
2342+
DiagnosticsLoggerFilteringByScopedPragmas(langVersion, scopedPragmas, diagnosticOptions, diagnosticsLogger) :> DiagnosticsLogger

src/Compiler/Driver/CompilerDiagnostics.fsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open System.Text
77
open FSharp.Compiler.CompilerConfig
88
open FSharp.Compiler.Diagnostics
99
open FSharp.Compiler.DiagnosticsLogger
10+
open FSharp.Compiler.Features
1011
open FSharp.Compiler.Syntax
1112
open FSharp.Compiler.Text
1213

@@ -84,7 +85,7 @@ type PhasedDiagnostic with
8485

8586
/// Get a diagnostics logger that filters the reporting of warnings based on scoped pragma information
8687
val GetDiagnosticsLoggerFilteringByScopedPragmas:
87-
checkFile: bool *
88+
langVersion: LanguageVersion *
8889
scopedPragmas: ScopedPragma list *
8990
diagnosticOptions: FSharpDiagnosticOptions *
9091
diagnosticsLogger: DiagnosticsLogger ->

src/Compiler/Driver/ParseAndCheckInputs.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ let ParseInput
511511
finally
512512
// OK, now commit the errors, since the ScopedPragmas will (hopefully) have been scraped
513513
let filteringDiagnosticsLogger =
514-
GetDiagnosticsLoggerFilteringByScopedPragmas(false, scopedPragmas, diagnosticOptions, diagnosticsLogger)
514+
GetDiagnosticsLoggerFilteringByScopedPragmas(lexbuf.LanguageVersion, scopedPragmas, diagnosticOptions, diagnosticsLogger)
515515

516516
delayLogger.CommitDelayedDiagnostics filteringDiagnosticsLogger
517517

@@ -1429,7 +1429,7 @@ let CheckOneInput
14291429

14301430
// Within a file, equip loggers to locally filter w.r.t. scope pragmas in each input
14311431
let DiagnosticsLoggerForInput (tcConfig: TcConfig, input: ParsedInput, oldLogger) =
1432-
GetDiagnosticsLoggerFilteringByScopedPragmas(false, input.ScopedPragmas, tcConfig.diagnosticsOptions, oldLogger)
1432+
GetDiagnosticsLoggerFilteringByScopedPragmas(tcConfig.langVersion, input.ScopedPragmas, tcConfig.diagnosticsOptions, oldLogger)
14331433

14341434
/// Typecheck a single file (or interactive entry into F# Interactive)
14351435
let CheckOneInputEntry (ctok, checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt) tcState input =

src/Compiler/Driver/fsc.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ let main2
745745
yield! pragmas
746746
]
747747

748-
GetDiagnosticsLoggerFilteringByScopedPragmas(true, scopedPragmas, tcConfig.diagnosticsOptions, oldLogger)
748+
GetDiagnosticsLoggerFilteringByScopedPragmas(tcConfig.langVersion, scopedPragmas, tcConfig.diagnosticsOptions, oldLogger)
749749

750750
SetThreadDiagnosticsLoggerNoUnwind diagnosticsLogger
751751

src/Compiler/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,3 +1782,4 @@ featureEmptyBodiedComputationExpressions,"Support for computation expressions wi
17821782
featureAllowAccessModifiersToAutoPropertiesGettersAndSetters,"Allow access modifiers to auto properties getters and setters"
17831783
3871,tcAccessModifiersNotAllowedInSRTPConstraint,"Access modifiers cannot be applied to an SRTP constraint."
17841784
featureAllowObjectExpressionWithoutOverrides,"Allow object expressions without overrides"
1785+
featureCheckFileBugFixed,"checkFile bug fixed"

src/Compiler/Facilities/LanguageFeatures.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type LanguageFeature =
9494
| ParsedHashDirectiveArgumentNonQuotes
9595
| EmptyBodiedComputationExpressions
9696
| AllowObjectExpressionWithoutOverrides
97+
| CheckFileBugFixed
9798

9899
/// LanguageVersion management
99100
type LanguageVersion(versionText) =
@@ -213,6 +214,7 @@ type LanguageVersion(versionText) =
213214
LanguageFeature.ParsedHashDirectiveArgumentNonQuotes, languageVersion90
214215
LanguageFeature.EmptyBodiedComputationExpressions, languageVersion90
215216
LanguageFeature.EnforceAttributeTargets, languageVersion90
217+
LanguageFeature.CheckFileBugFixed, languageVersion90
216218

217219
// F# preview
218220
LanguageFeature.UnmanagedConstraintCsharpInterop, previewVersion // not enabled because: https://github.com/dotnet/fsharp/issues/17509
@@ -375,6 +377,7 @@ type LanguageVersion(versionText) =
375377
| LanguageFeature.ParsedHashDirectiveArgumentNonQuotes -> FSComp.SR.featureParsedHashDirectiveArgumentNonString ()
376378
| LanguageFeature.EmptyBodiedComputationExpressions -> FSComp.SR.featureEmptyBodiedComputationExpressions ()
377379
| LanguageFeature.AllowObjectExpressionWithoutOverrides -> FSComp.SR.featureAllowObjectExpressionWithoutOverrides ()
380+
| LanguageFeature.CheckFileBugFixed -> FSComp.SR.featureCheckFileBugFixed ()
378381

379382
/// Get a version string associated with the given feature.
380383
static member GetFeatureVersionString feature =

0 commit comments

Comments
 (0)