Skip to content

Commit ac3d3c8

Browse files
Martin521psfinaki
andauthored
Make the interaction between #line and #nowarn directives consistent (#17649)
* fix the checkFile bug * change the feature flag name * updated xlf files * Another small name change --------- Co-authored-by: Petr <[email protected]>
1 parent e42cff6 commit ac3d3c8

30 files changed

+152
-22
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: 10 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,13 @@ 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 needCompatibilityWithEarlierInconsistentInteraction =
2308+
not (langVersion.SupportsFeature LanguageFeature.ConsistentNowarnLineDirectiveInteraction)
2309+
23132310
let mutable realErrorPresent = false
23142311

23152312
override _.DiagnosticSink(diagnostic: PhasedDiagnostic, severity) =
@@ -2323,12 +2320,10 @@ type DiagnosticsLoggerFilteringByScopedPragmas
23232320
match diagnostic.Range with
23242321
| Some m ->
23252322
scopedPragmas
2326-
|> List.exists (fun pragma ->
2327-
let (ScopedPragma.WarningOff(pragmaRange, warningNumFromPragma)) = pragma
2328-
2323+
|> List.exists (fun (ScopedPragma.WarningOff(pragmaRange, warningNumFromPragma)) ->
23292324
warningNum = warningNumFromPragma
2330-
&& (not checkFile || m.FileIndex = pragmaRange.FileIndex)
2331-
&& posGeq m.Start pragmaRange.Start)
2325+
&& (needCompatibilityWithEarlierInconsistentInteraction
2326+
|| m.FileIndex = pragmaRange.FileIndex && posGeq m.Start pragmaRange.Start))
23322327
|> not
23332328
| None -> true
23342329

@@ -2344,5 +2339,5 @@ type DiagnosticsLoggerFilteringByScopedPragmas
23442339

23452340
override _.CheckForRealErrorsIgnoringWarnings = realErrorPresent
23462341

2347-
let GetDiagnosticsLoggerFilteringByScopedPragmas (checkFile, scopedPragmas, diagnosticOptions, diagnosticsLogger) =
2348-
DiagnosticsLoggerFilteringByScopedPragmas(checkFile, scopedPragmas, diagnosticOptions, diagnosticsLogger) :> DiagnosticsLogger
2342+
let GetDiagnosticsLoggerFilteringByScopedPragmas (langVersion, scopedPragmas, diagnosticOptions, diagnosticsLogger) =
2343+
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,4 +1783,5 @@ featureEmptyBodiedComputationExpressions,"Support for computation expressions wi
17831783
featureAllowAccessModifiersToAutoPropertiesGettersAndSetters,"Allow access modifiers to auto properties getters and setters"
17841784
3871,tcAccessModifiersNotAllowedInSRTPConstraint,"Access modifiers cannot be applied to an SRTP constraint."
17851785
featureAllowObjectExpressionWithoutOverrides,"Allow object expressions without overrides"
1786-
3872,tcPartialActivePattern,"Multi-case partial active patterns are not supported. Consider using a single-case partial active pattern or a full active pattern."
1786+
3872,tcPartialActivePattern,"Multi-case partial active patterns are not supported. Consider using a single-case partial active pattern or a full active pattern."
1787+
featureConsistentNowarnLineDirectiveInteraction,"The interaction between #nowarn and #line is now consistent."

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+
| ConsistentNowarnLineDirectiveInteraction
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.ConsistentNowarnLineDirectiveInteraction, 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.ConsistentNowarnLineDirectiveInteraction -> FSComp.SR.featureConsistentNowarnLineDirectiveInteraction ()
378381

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

src/Compiler/Facilities/LanguageFeatures.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type LanguageFeature =
8585
| ParsedHashDirectiveArgumentNonQuotes
8686
| EmptyBodiedComputationExpressions
8787
| AllowObjectExpressionWithoutOverrides
88+
| ConsistentNowarnLineDirectiveInteraction
8889

8990
/// LanguageVersion management
9091
type LanguageVersion =

src/Compiler/Service/IncrementalBuild.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ type BoundModel private (
259259

260260
IncrementalBuilderEventTesting.MRU.Add(IncrementalBuilderEventTesting.IBETypechecked fileName)
261261
let capturingDiagnosticsLogger = CapturingDiagnosticsLogger("TypeCheck")
262-
let diagnosticsLogger = GetDiagnosticsLoggerFilteringByScopedPragmas(false, input.ScopedPragmas, tcConfig.diagnosticsOptions, capturingDiagnosticsLogger)
262+
let diagnosticsLogger = GetDiagnosticsLoggerFilteringByScopedPragmas(tcConfig.langVersion, input.ScopedPragmas, tcConfig.diagnosticsOptions, capturingDiagnosticsLogger)
263263
use _ = new CompilationGlobalsScope(diagnosticsLogger, BuildPhase.TypeCheck)
264264

265265
beforeFileChecked.Trigger fileName

src/Compiler/Service/TransparentCompiler.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,12 @@ type internal TransparentCompiler
12991299
let diagnosticsLogger = errHandler.DiagnosticsLogger
13001300

13011301
let diagnosticsLogger =
1302-
GetDiagnosticsLoggerFilteringByScopedPragmas(false, input.ScopedPragmas, tcConfig.diagnosticsOptions, diagnosticsLogger)
1302+
GetDiagnosticsLoggerFilteringByScopedPragmas(
1303+
tcConfig.langVersion,
1304+
input.ScopedPragmas,
1305+
tcConfig.diagnosticsOptions,
1306+
diagnosticsLogger
1307+
)
13031308

13041309
use _ = new CompilationGlobalsScope(diagnosticsLogger, BuildPhase.TypeCheck)
13051310

src/Compiler/pars.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" // generated code has lots of unused "parseState"
67
#nowarn "3261" // the generated code would need to properly annotate nulls, e.g. changing System.Object to `obj|null`
78

src/Compiler/pppars.fsy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
%{
44
open FSharp.Compiler.DiagnosticsLogger
55

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

89
let dummy = IfdefId("DUMMY")

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ko.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.pl.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ru.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.tr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)