Skip to content

Commit 1bcc338

Browse files
authored
Merge pull request #143 from nojaf/fix-142
Check if DU type is not generic parameter in StructDiscriminatedUnionAnalyzer.
2 parents 32f41e7 + 8ae6453 commit 1bcc338

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

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.14.2 - 2025-03-18
4+
5+
### Fixed
6+
7+
* InvalidOperationException on generic discriminated unions. [#142](https://github.com/ionide/ionide-analyzers/issues/142)
38

49
## 0.14.1 - 2025-03-06
510

src/Ionide.Analyzers/Suggestion/StructDiscriminatedUnionAnalyzer.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ let private analyze
110110

111111
if ff.FieldType.IsFunctionType || ff.FieldType.IsAnonRecordType then
112112
false
113-
elif not (Seq.isEmpty ff.FieldType.GenericArguments) then
113+
elif
114+
ff.FieldType.IsGenericParameter
115+
|| not (Seq.isEmpty ff.FieldType.GenericArguments)
116+
then
114117
false
115118
else
116119

tests/Ionide.Analyzers.Tests/Suggestion/StructDiscriminatedUnionAnalyzerTests.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,19 @@ type TwoCaseDU = | Empty | Full of int[]
250250
let! msgs = structDiscriminatedUnionCliAnalyzer ctx
251251
Assert.That(msgs, Is.Empty)
252252
}
253+
254+
[<Test>]
255+
let ``negative: generic types`` () =
256+
async {
257+
let source =
258+
"""module Foo
259+
260+
type Validated<'valid, 'invalid> =
261+
| Valid of 'valid
262+
| Invalid of 'invalid
263+
"""
264+
265+
let ctx = getContext projectOptions source
266+
let! msgs = structDiscriminatedUnionCliAnalyzer ctx
267+
Assert.That(msgs, Is.Empty)
268+
}

0 commit comments

Comments
 (0)