Skip to content

Commit 37e99ac

Browse files
authored
Ensure access path is from FSharp namespace in VirtualCallAnalyzer (#87)
* Ensure access path is from FSharp namespace in VirtualCallAnalyzer * Add changelog entry
1 parent e4d4c63 commit 37e99ac

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.12.1 - 2024-01-08
4+
5+
### Fixed
6+
* VirtualCall analyzer suggests quickfix on Collections.Generic.List. [#86](https://github.com/G-Research/fsharp-analyzers/issues/86)
7+
38
## 0.12.0 - 2024-11-20
49

510
### Changed

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.300",
3+
"version": "8.0.400",
44
"allowPrerelease": true,
55
"rollForward": "latestMinor"
66
}

src/FSharp.Analyzers/VirtualCallAnalyzer.fs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,27 @@ let (|CoerceToSeq|_|) (includeFromSet : bool) (expr : FSharpExpr) =
2929
StringComparison.Ordinal
3030
)
3131
then
32-
e.Type.TypeDefinition.AbbreviatedType.TypeDefinition.LogicalName
32+
Some e.Type.TypeDefinition.AbbreviatedType.TypeDefinition.LogicalName
33+
elif
34+
(let accessPath = e.Type.TypeDefinition.AccessPath in
35+
36+
accessPath = "Microsoft.FSharp.Collections"
37+
|| accessPath = "Microsoft.FSharp.Core")
38+
then
39+
Some e.Type.TypeDefinition.LogicalName
3340
else
34-
e.Type.TypeDefinition.LogicalName
35-
36-
match coercedValueTypeName with
37-
| "[]`1"
38-
| "array`1" -> Some "Array"
39-
| "list`1"
40-
| "List`1" -> Some "List"
41-
| "Set`1" when includeFromSet -> Some "Set"
42-
| _ -> None
41+
None
42+
43+
coercedValueTypeName
44+
|> Option.bind (fun coercedValueTypeName ->
45+
match coercedValueTypeName with
46+
| "[]`1"
47+
| "array`1" -> Some "Array"
48+
| "list`1"
49+
| "List`1" -> Some "List"
50+
| "Set`1" when includeFromSet -> Some "Set"
51+
| _ -> None
52+
)
4353
| _ -> None
4454

4555
let seqFuncsWithEquivalentsInAllCollections =

tests/FSharp.Analyzers.Tests/Common.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open NUnit.Framework
88
open FSharp.Analyzers.SDK
99

1010
[<Literal>]
11-
let framework = "net7.0"
11+
let framework = "net8.0"
1212

1313
let shouldUpdateBaseline () =
1414
Environment.GetEnvironmentVariable "TEST_UPDATE_BSL"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module C
2+
3+
let list = System.Collections.Generic.List<int>()
4+
let h = Seq.head list

0 commit comments

Comments
 (0)