Skip to content

Commit 7b2df5c

Browse files
committed
fix merge issues
2 parents c3d61e0 + 87587f8 commit 7b2df5c

File tree

3 files changed

+69
-12
lines changed

3 files changed

+69
-12
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Better generic unmanaged structs handling. ([Language suggestion #692](https://github.com/fsharp/fslang-suggestions/issues/692), [PR #12154](https://github.com/dotnet/fsharp/pull/12154))
44
* Deprecate places where `seq` can be omitted. ([Language suggestion #1033](https://github.com/fsharp/fslang-suggestions/issues/1033), [PR #17772](https://github.com/dotnet/fsharp/pull/17772))
55
* Added type conversions cache, only enabled for compiler runs ([PR#17668](https://github.com/dotnet/fsharp/pull/17668))
6-
* Introduction of the `#warnon` compiler directive, enabling scoped nowarn / warnon sections according to [RFC FS-1146](https://github.com/fsharp/fslang-design/pull/782/files). ([Language suggestion #278](https://github.com/fsharp/fslang-suggestions/issues/278), [PR #17507](https://github.com/dotnet/fsharp/pull/17507))
76

87
### Fixed
98
* Warn on uppercase identifiers in patterns. ([PR #15816](https://github.com/dotnet/fsharp/pull/15816))

src/Compiler/Driver/CompilerConfig.fs

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,61 @@ let ResolveFileUsingPaths (paths, m, fileName) =
9292
let searchMessage = String.concat "\n " paths
9393
raise (FileNameNotResolved(fileName, searchMessage, m))
9494

95-
let GetWarningNumber (numberString) =
96-
let trimPrefix (s: string) =
97-
if s.StartsWithOrdinal "FS" then s[2..] else s
95+
[<RequireQualifiedAccess>]
96+
type WarningNumberSource =
97+
| CommandLineOption
98+
| CompilerDirective
99+
100+
[<RequireQualifiedAccess>]
101+
type WarningDescription =
102+
| Int32 of int
103+
| String of string
104+
| Ident of Ident
105+
106+
let GetWarningNumber (m, description: WarningDescription, langVersion: LanguageVersion, source: WarningNumberSource) =
107+
let argFeature = LanguageFeature.ParsedHashDirectiveArgumentNonQuotes
108+
109+
let parse (numStr: string) =
110+
let trimPrefix (s: string) =
111+
if s.StartsWithOrdinal "FS" then s[2..] else s
112+
113+
let tryParseIntWithFailAction (s: string) (failAction: unit -> unit) =
114+
match Int32.TryParse s with
115+
| true, n -> Some n
116+
| false, _ ->
117+
failAction ()
118+
None
119+
120+
let warnInvalid () =
121+
warning (Error(FSComp.SR.buildInvalidWarningNumber numStr, m))
98122

99-
let tryParseInt (s: string) =
100-
match Int32.TryParse s with
101-
| true, n -> Some n
102-
| false, _ -> None
123+
if source = WarningNumberSource.CommandLineOption then
124+
tryParseIntWithFailAction (trimPrefix numStr) id
125+
elif langVersion.SupportsFeature(argFeature) then
126+
tryParseIntWithFailAction (trimPrefix numStr) warnInvalid
127+
else
128+
tryParseIntWithFailAction numStr id
103129

104-
tryParseInt (trimPrefix numberString)
130+
match description with
131+
| WarningDescription.Int32 n ->
132+
if tryCheckLanguageFeatureAndRecover langVersion argFeature m then
133+
Some n
134+
else
135+
None
136+
| WarningDescription.String s ->
137+
if
138+
source = WarningNumberSource.CompilerDirective
139+
&& not (langVersion.SupportsFeature argFeature)
140+
&& s.StartsWithOrdinal "FS"
141+
then
142+
warning (Error(FSComp.SR.buildInvalidWarningNumber s, m))
143+
144+
parse s
145+
| WarningDescription.Ident ident ->
146+
if tryCheckLanguageFeatureAndRecover langVersion argFeature m then
147+
parse ident.idText
148+
else
149+
None
105150

106151
let ComputeMakePathAbsolute implicitIncludeDir (path: string) =
107152
try
@@ -927,7 +972,7 @@ type TcConfigBuilder =
927972
member tcConfigB.TurnWarningOff(m: range, s: string) =
928973
use _ = UseBuildPhase BuildPhase.Parameter
929974

930-
match GetWarningNumber s with
975+
match GetWarningNumber(m, WarningDescription.String s, tcConfigB.langVersion, WarningNumberSource.CommandLineOption) with
931976
| None -> ()
932977
| Some n ->
933978
// nowarn:62 turns on mlCompatibility, e.g. shows ML compat items in intellisense menus
@@ -942,7 +987,7 @@ type TcConfigBuilder =
942987
member tcConfigB.TurnWarningOn(m: range, s: string) =
943988
use _ = UseBuildPhase BuildPhase.Parameter
944989

945-
match GetWarningNumber s with
990+
match GetWarningNumber(m, WarningDescription.String s, tcConfigB.langVersion, WarningNumberSource.CommandLineOption) with
946991
| None -> ()
947992
| Some n ->
948993
// warnon 62 turns on mlCompatibility, e.g. shows ML compat items in intellisense menus

src/Compiler/Driver/CompilerConfig.fsi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,20 @@ val TryResolveFileUsingPaths: paths: string seq * m: range * fileName: string ->
927927

928928
val ResolveFileUsingPaths: paths: string seq * m: range * fileName: string -> string
929929

930-
val GetWarningNumber: string -> int option
930+
[<RequireQualifiedAccess>]
931+
type WarningNumberSource =
932+
| CommandLineOption
933+
| CompilerDirective
934+
935+
[<RequireQualifiedAccess>]
936+
type WarningDescription =
937+
| Int32 of int
938+
| String of string
939+
| Ident of Ident
940+
941+
val GetWarningNumber:
942+
m: range * description: WarningDescription * langVersion: LanguageVersion * source: WarningNumberSource ->
943+
int option
931944

932945
/// Get the name used for FSharp.Core
933946
val GetFSharpCoreLibraryName: unit -> string

0 commit comments

Comments
 (0)