Skip to content

Commit 723b1dc

Browse files
authored
More accurate range for FS0053: Discriminated union cases and exception labels must be uppercase identifiers (#15545)
* Use idRange instead of parent range * Update ProposeUppercaseLabelTests
1 parent edbbecc commit 723b1dc

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ module TcExceptionDeclarations =
22492249

22502250
let TcExnDefnCore_Phase1A cenv env parent (SynExceptionDefnRepr(Attributes synAttrs, SynUnionCase(ident= SynIdent(id,_)), _, xmlDoc, vis, m)) =
22512251
let attrs = TcAttributes cenv env AttributeTargets.ExnDecl synAttrs
2252-
if not (String.isLeadingIdentifierCharacterUpperCase id.idText) then errorR(NotUpperCaseConstructor m)
2252+
if not (String.isLeadingIdentifierCharacterUpperCase id.idText) then errorR(NotUpperCaseConstructor id.idRange)
22532253
let vis, cpath = ComputeAccessAndCompPath env None m vis None parent
22542254
let vis = TcRecdUnionAndEnumDeclarations.CombineReprAccess parent vis
22552255
CheckForDuplicateConcreteType env (id.idText + "Exception") id.idRange

tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/ExceptionDefinitions/ExceptionDefinitions.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ module ExceptionDefinition =
147147
|> compile
148148
|> shouldFail
149149
|> withDiagnostics [
150-
(Error 53, Line 9, Col 1, Line 9, Col 19, "Discriminated union cases and exception labels must be uppercase identifiers")
151-
(Error 53, Line 10, Col 1, Line 10, Col 19, "Discriminated union cases and exception labels must be uppercase identifiers")
150+
(Error 53, Line 9, Col 11, Line 9, Col 12, "Discriminated union cases and exception labels must be uppercase identifiers")
151+
(Error 53, Line 10, Col 11, Line 10, Col 12, "Discriminated union cases and exception labels must be uppercase identifiers")
152152
]
153153

154154
// SOURCE=E_BeginWithUppercase02.fsx SCFLAGS="--test:ErrorRanges" # E_BeginWithUppercase02.fsx
@@ -310,7 +310,7 @@ module ExceptionDefinition =
310310
|> compile
311311
|> shouldFail
312312
|> withDiagnostics [
313-
(Error 53, Line 8, Col 1, Line 8, Col 39, "Discriminated union cases and exception labels must be uppercase identifiers")
313+
(Error 53, Line 8, Col 11, Line 8, Col 29, "Discriminated union cases and exception labels must be uppercase identifiers")
314314
]
315315

316316
// SOURCE=E_Undefined.fsx SCFLAGS=--test:ErrorRanges # E_Undefined.fsx

vsintegration/tests/FSharp.Editor.Tests/CodeFixes/ProposeUppercaseLabelTests.fs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,21 @@ type MyNumber = Number of int
3232
Assert.Equal(expected, actual)
3333

3434
[<Fact>]
35-
let ``Doesn't fix FS0053 for exceptions`` () =
35+
let ``Fix FS0053 for exceptions`` () =
3636
let code =
3737
"""
3838
exception lowException of string
3939
"""
4040

41-
let expected = None
41+
let expected =
42+
Some
43+
{
44+
Message = "Replace with 'LowException'"
45+
FixedCode =
46+
"""
47+
exception LowException of string
48+
"""
49+
}
4250

4351
let actual = codeFix |> tryFix code diagnostic
4452

0 commit comments

Comments
 (0)