diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index c2ff7d12589..d4afcdadb23 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -2185,6 +2185,8 @@ type TcResultsSinkImpl(tcGlobals, ?sourceText: ISourceText) = let capturedOpenDeclarations = ResizeArray() let capturedFormatSpecifierLocations = ResizeArray<_>() + let capturedFormatSpecifierRanges = HashSet() + let capturedNameResolutionIdentifiers = HashSet { new IEqualityComparer<_> with @@ -2289,7 +2291,8 @@ type TcResultsSinkImpl(tcGlobals, ?sourceText: ISourceText) = capturedMethodGroupResolutions.Add(CapturedNameResolution(itemMethodGroup, [], occurrenceType, nenv, ad, m)) member sink.NotifyFormatSpecifierLocation(m, numArgs) = - capturedFormatSpecifierLocations.Add((m, numArgs)) + if capturedFormatSpecifierRanges.Add(m) then + capturedFormatSpecifierLocations.Add((m, numArgs)) member sink.NotifyRelatedSymbolUse(m, item, kind) = if allowedRange m then diff --git a/tests/FSharp.Compiler.Service.Tests/EditorTests.fs b/tests/FSharp.Compiler.Service.Tests/EditorTests.fs index 44be1a5cfef..f9c1da195fe 100644 --- a/tests/FSharp.Compiler.Service.Tests/EditorTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/EditorTests.fs @@ -541,6 +541,19 @@ let _ = debug "[LanguageService] Type checking fails for '%s' with content=%A an (4, 82, 4, 84, 1); (4, 108, 4, 110, 1)|] +[] +let ``Format specifier locations not duplicated in CE`` () = + let input = "let _ = seq { sprintf \"%d\" 1 }" + let file = "/home/user/Test.fsx" + let _parseResult, typeCheckResults = parseAndCheckScript(file, input) + + let locations = typeCheckResults.GetFormatSpecifierLocationsAndArity() + let percentD = + locations + |> Array.filter (fun (r, _) -> r.StartColumn = 23) + + Assert.Equal(1, percentD.Length) + #if ASSUME_PREVIEW_FSHARP_CORE [] let ``Printf specifiers for regular and verbatim interpolated strings`` () =