Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* Fix excessive StackGuard thread jumping ([PR #18971](https://github.com/dotnet/fsharp/pull/18971))
* Checking: Fix checking nested fields for records and anonymous ([PR #18964](https://github.com/dotnet/fsharp/pull/18964))
* Fix name is bound multiple times is not reported in 'as' pattern ([PR #18984](https://github.com/dotnet/fsharp/pull/18984))
* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010))
* Fix: warn FS0049 on upper union case label. ([PR #19003](https://github.com/dotnet/fsharp/pull/19003))
* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010))

### Added

Expand Down
13 changes: 8 additions & 5 deletions src/Compiler/Checking/CheckPatterns.fs
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,18 @@ and TcPatNamedAs warnOnUpper cenv env valReprInfo vFlags patEnv ty synInnerPat i
phase2, acc

and TcPatUnnamedAs warnOnUpper cenv env vFlags patEnv ty pat1 pat2 m =
let pats = [pat1; pat2]
let warnOnUpper =
// Type-check pat1 with the original warnOnUpper flag (to warn on uppercase identifiers)
let pat1R, patEnv1 = TcPat warnOnUpper cenv env None vFlags patEnv ty pat1

// For pat2 (the binding variable like UppercaseIdentifier as Foo), suppress uppercase warnings if the feature is enabled
let warnOnUpperForPat2 =
if cenv.g.langVersion.SupportsFeature(LanguageFeature.DontWarnOnUppercaseIdentifiersInBindingPatterns) then
AllIdsOK
else
warnOnUpper

let patsR, patEnvR = TcPatterns warnOnUpper cenv env vFlags patEnv (List.map (fun _ -> ty) pats) pats
let phase2 values = TPat_conjs(List.map (fun f -> f values) patsR, m)
let pat2R, patEnvR = TcPat warnOnUpperForPat2 cenv env None vFlags patEnv1 ty pat2
let phase2 values = TPat_conjs([pat1R values; pat2R values], m)
phase2, patEnvR

and TcPatNamed warnOnUpper cenv env vFlags patEnv id ty isMemberThis vis valReprInfo m =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/SyntaxTree/SyntaxTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ type SynMatchClause =

member this.IsTrueMatchClause =
let (SynMatchClause(trivia = trivia)) = this
trivia.BarRange.IsSome && trivia.ArrowRange.IsSome
trivia.ArrowRange.IsSome

member this.Range =
match this with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,10 @@ module BindingExpressions =
|> asExe
|> withOptions ["--test:ErrorRanges"]
|> typecheck
|> shouldSucceed
|> shouldFail
|> withDiagnostics [
(Warning 49, Line 61, Col 6, Line 61, Col 8, "Uppercase variable identifiers should not generally be used in patterns, and may indicate a missing open declaration or a misspelt pattern name.");
(Warning 49, Line 122, Col 6, Line 122, Col 8, "Uppercase variable identifiers should not generally be used in patterns, and may indicate a missing open declaration or a misspelt pattern name.");
(Warning 49, Line 125, Col 6, Line 125, Col 8, "Uppercase variable identifiers should not generally be used in patterns, and may indicate a missing open declaration or a misspelt pattern name.");
(Warning 49, Line 128, Col 6, Line 128, Col 8, "Uppercase variable identifiers should not generally be used in patterns, and may indicate a missing open declaration or a misspelt pattern name.")
]

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ let customerId = CustomerId("123")
match customerId with
| CustomerId BBB -> ()

match 42 with | UpperCase -> ()

match 42 with UpperCase -> ()

type Record = { Name: string; Age: int }

match { Name = "Alice"; Age = 30 } with
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

let test1 x =
match x with
| UndefinedCase -> 1

let test2 x =
match x with UndefinedCase -> 1

let test3 = function | UndefinedCase -> 1

let test4 = function UndefinedCase -> 1

let test5 () =
try failwith "test"
with | UndefinedException -> 1

let test6 () =
try failwith "test"
with UndefinedException -> 1

let test7 () =
try failwith "test"
with UndefinedException as Foo -> 1

let test8 () =
try failwith "test"
with | UndefinedException as Foo -> 1
2 changes: 2 additions & 0 deletions tests/fsharp/typecheck/sigs/neg07.bsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
neg07.fs(7,10,7,29): typecheck error FS0049: Uppercase variable identifiers should not generally be used in patterns, and may indicate a missing open declaration or a misspelt pattern name.

neg07.fs(24,13,24,23): typecheck error FS0039: The value or constructor 'UnionCase1' is not defined. Maybe you want one of the following:
X.UnionCase1

Expand Down
Loading