Skip to content

Commit

Permalink
fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin521 committed Nov 8, 2024
2 parents c3d61e0 + 87587f8 commit 7b2df5c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 12 deletions.
1 change: 0 additions & 1 deletion docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* 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))
* 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))
* Added type conversions cache, only enabled for compiler runs ([PR#17668](https://github.com/dotnet/fsharp/pull/17668))
* 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))

### Fixed
* Warn on uppercase identifiers in patterns. ([PR #15816](https://github.com/dotnet/fsharp/pull/15816))
Expand Down
65 changes: 55 additions & 10 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,61 @@ let ResolveFileUsingPaths (paths, m, fileName) =
let searchMessage = String.concat "\n " paths
raise (FileNameNotResolved(fileName, searchMessage, m))

let GetWarningNumber (numberString) =
let trimPrefix (s: string) =
if s.StartsWithOrdinal "FS" then s[2..] else s
[<RequireQualifiedAccess>]
type WarningNumberSource =
| CommandLineOption
| CompilerDirective

[<RequireQualifiedAccess>]
type WarningDescription =
| Int32 of int
| String of string
| Ident of Ident

let GetWarningNumber (m, description: WarningDescription, langVersion: LanguageVersion, source: WarningNumberSource) =
let argFeature = LanguageFeature.ParsedHashDirectiveArgumentNonQuotes

let parse (numStr: string) =
let trimPrefix (s: string) =
if s.StartsWithOrdinal "FS" then s[2..] else s

let tryParseIntWithFailAction (s: string) (failAction: unit -> unit) =
match Int32.TryParse s with
| true, n -> Some n
| false, _ ->
failAction ()
None

let warnInvalid () =
warning (Error(FSComp.SR.buildInvalidWarningNumber numStr, m))

let tryParseInt (s: string) =
match Int32.TryParse s with
| true, n -> Some n
| false, _ -> None
if source = WarningNumberSource.CommandLineOption then
tryParseIntWithFailAction (trimPrefix numStr) id
elif langVersion.SupportsFeature(argFeature) then
tryParseIntWithFailAction (trimPrefix numStr) warnInvalid
else
tryParseIntWithFailAction numStr id

tryParseInt (trimPrefix numberString)
match description with
| WarningDescription.Int32 n ->
if tryCheckLanguageFeatureAndRecover langVersion argFeature m then
Some n
else
None
| WarningDescription.String s ->
if
source = WarningNumberSource.CompilerDirective
&& not (langVersion.SupportsFeature argFeature)
&& s.StartsWithOrdinal "FS"
then
warning (Error(FSComp.SR.buildInvalidWarningNumber s, m))

parse s
| WarningDescription.Ident ident ->
if tryCheckLanguageFeatureAndRecover langVersion argFeature m then
parse ident.idText
else
None

let ComputeMakePathAbsolute implicitIncludeDir (path: string) =
try
Expand Down Expand Up @@ -927,7 +972,7 @@ type TcConfigBuilder =
member tcConfigB.TurnWarningOff(m: range, s: string) =
use _ = UseBuildPhase BuildPhase.Parameter

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

match GetWarningNumber s with
match GetWarningNumber(m, WarningDescription.String s, tcConfigB.langVersion, WarningNumberSource.CommandLineOption) with
| None -> ()
| Some n ->
// warnon 62 turns on mlCompatibility, e.g. shows ML compat items in intellisense menus
Expand Down
15 changes: 14 additions & 1 deletion src/Compiler/Driver/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,20 @@ val TryResolveFileUsingPaths: paths: string seq * m: range * fileName: string ->

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

val GetWarningNumber: string -> int option
[<RequireQualifiedAccess>]
type WarningNumberSource =
| CommandLineOption
| CompilerDirective

[<RequireQualifiedAccess>]
type WarningDescription =
| Int32 of int
| String of string
| Ident of Ident

val GetWarningNumber:
m: range * description: WarningDescription * langVersion: LanguageVersion * source: WarningNumberSource ->
int option

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

0 comments on commit 7b2df5c

Please sign in to comment.