1
1
module ErrorMessages.UnionCasePatternMatchingErrors
2
2
3
+ open FSharp.Test
3
4
open Xunit
4
5
open FSharp.Test .Compiler
5
6
@@ -86,8 +87,7 @@ let myVal =
86
87
|> typecheck
87
88
|> shouldFail
88
89
|> withSingleDiagnostic ( Warning 3548 , Line 9 , Col 7 , Line 9 , Col 10 , " Pattern discard is not allowed for union case that takes no data." )
89
-
90
-
90
+
91
91
[<Fact>]
92
92
let ``Union Pattern discard allowed for union case that takes no data with Lang version 7`` () =
93
93
FSharp """
@@ -245,6 +245,30 @@ let myVal =
245
245
( Warning 3548 , Line 17 , Col 20 , Line 17 , Col 23 , " Pattern discard is not allowed for union case that takes no data." )
246
246
]
247
247
248
+ [<Fact>]
249
+ let ``Multiple pattern discards not allowed for union case that takes no data with Lang 7`` () =
250
+ FSharp """
251
+ module Tests
252
+ type U =
253
+ | A
254
+ | B of int * int * int
255
+ | C of int * int * int
256
+
257
+ type V =
258
+ | D
259
+
260
+ let a : U = A
261
+ let d : V = D
262
+
263
+ let myVal =
264
+ match a, d with
265
+ | A _, D -> 15
266
+ | B (x, _, _), D _ -> 16
267
+ | C _, _ -> 17"""
268
+ |> withLangVersion70
269
+ |> typecheck
270
+ |> shouldSucceed
271
+
248
272
[<Fact>]
249
273
let ``Multiple function pattern discards is not allowed for union case that takes no data with Lang preview`` () =
250
274
FSharp """
@@ -274,42 +298,82 @@ let myVal =
274
298
]
275
299
276
300
[<Fact>]
277
- let ``Pattern discard allowed for single - case unions when using them as a deconstruct syntax in functions with Lang 7`` () =
301
+ let ``Multiple function pattern discards is not allowed for union case that takes no data with Lang 7`` () =
278
302
FSharp """
279
303
module Tests
280
- type MyWrapper = A
304
+ type U =
305
+ | A
306
+ | B of int * int * int
307
+ | C of int * int * int
308
+
309
+ type V =
310
+ | D
311
+
312
+ let a : U = A
281
313
282
- let myDiscardedArgFunc(A _) = 5+5"""
314
+ let d : V = D
315
+
316
+ let myVal =
317
+ function
318
+ | A _, D -> 15
319
+ | B (x, _, _), D _ -> 16
320
+ | C _, _ -> 17"""
283
321
|> withLangVersion70
284
322
|> typecheck
285
323
|> shouldSucceed
286
-
287
- [<Fact>]
288
- let ``Pattern named not allowed for single - case unions when using them as a deconstruct syntax in functions with Lang 7`` () =
289
- FSharp """
290
- module Tests
291
- type MyWrapper = A
292
-
293
- let myFunc(A a) = 5+5"""
324
+
325
+ [<Theory; Directory(__ SOURCE_ DIRECTORY__, Includes=[| " E_UnionCaseTakesNoArguments.fs" |]) >]
326
+ let ``Pattern named not allowed union case does not take any arguments with Lang 7`` compilation =
327
+ compilation
328
+ |> asFs
294
329
|> withLangVersion70
330
+ |> withOptions [ " --nowarn:25" ]
295
331
|> typecheck
296
332
|> shouldFail
297
333
|> withDiagnostics [
298
- ( Error 725 , Line 5 , Col 12 , Line 5 , Col 15 , " This union case does not take arguments" )
334
+ ( Error 725 , Line 8 , Col 3 , Line 8 , Col 9 , " This union case does not take arguments" );
335
+ ( Error 725 , Line 11 , Col 3 , Line 11 , Col 14 , " This union case does not take arguments" )
336
+ ( Error 725 , Line 14 , Col 3 , Line 14 , Col 10 , " This union case does not take arguments" )
337
+ ( Error 725 , Line 17 , Col 3 , Line 17 , Col 12 , " This union case does not take arguments" )
338
+ ( Error 725 , Line 20 , Col 3 , Line 20 , Col 17 , " This union case does not take arguments" )
339
+ ( Error 725 , Line 23 , Col 3 , Line 23 , Col 13 , " This union case does not take arguments" )
340
+ ( Error 725 , Line 26 , Col 3 , Line 26 , Col 14 , " This union case does not take arguments" )
341
+ ( Error 725 , Line 29 , Col 3 , Line 29 , Col 13 , " This union case does not take arguments" )
342
+ ( Error 725 , Line 35 , Col 3 , Line 35 , Col 9 , " This union case does not take arguments" )
343
+ ( Error 725 , Line 38 , Col 3 , Line 38 , Col 14 , " This union case does not take arguments" )
344
+ ( Error 725 , Line 42 , Col 3 , Line 42 , Col 11 , " This union case does not take arguments" )
345
+ ( Error 725 , Line 48 , Col 3 , Line 48 , Col 8 , " This union case does not take arguments" )
346
+ ( Error 725 , Line 51 , Col 3 , Line 51 , Col 7 , " This union case does not take arguments" )
347
+ ( Error 725 , Line 55 , Col 25 , Line 55 , Col 28 , " This union case does not take arguments" )
348
+ ( Error 725 , Line 57 , Col 25 , Line 57 , Col 29 , " This union case does not take arguments" )
349
+ ( Error 725 , Line 59 , Col 24 , Line 59 , Col 32 , " This union case does not take arguments" )
299
350
]
300
-
301
- [<Fact>]
302
- let ``Pattern discard or named are not allowed for single - case union case that takes no data with Lang preview`` () =
303
- FSharp """
304
- module Tests
305
- type MyWrapper = A
306
-
307
- let myFunc(A a) = 5+5
308
- let myDiscardedArgFunc(A _) = 5+5"""
351
+
352
+ [<Theory; Directory(__ SOURCE_ DIRECTORY__, Includes=[| " E_UnionCaseTakesNoArguments.fs" |]) >]
353
+ let ``Pattern named not allowed union case does not take any arguments with Lang preview`` compilation =
354
+ compilation
355
+ |> asFs
309
356
|> withLangVersionPreview
357
+ |> withOptions [ " --nowarn:25" ]
310
358
|> typecheck
311
359
|> shouldFail
312
360
|> withDiagnostics [
313
- ( Warning 3548 , Line 5 , Col 12 , Line 5 , Col 15 , " Pattern discard is not allowed for union case that takes no data." )
314
- ( Warning 3548 , Line 6 , Col 24 , Line 6 , Col 27 , " Pattern discard is not allowed for union case that takes no data." )
361
+ ( Error 725 , Line 8 , Col 3 , Line 8 , Col 9 , " This union case does not take arguments" )
362
+ ( Error 725 , Line 11 , Col 3 , Line 11 , Col 14 , " This union case does not take arguments" )
363
+ ( Error 725 , Line 14 , Col 3 , Line 14 , Col 10 , " This union case does not take arguments" )
364
+ ( Error 725 , Line 17 , Col 3 , Line 17 , Col 12 , " This union case does not take arguments" )
365
+ ( Error 725 , Line 20 , Col 3 , Line 20 , Col 17 , " This union case does not take arguments" )
366
+ ( Error 725 , Line 23 , Col 3 , Line 23 , Col 13 , " This union case does not take arguments" )
367
+ ( Error 725 , Line 26 , Col 3 , Line 26 , Col 14 , " This union case does not take arguments" )
368
+ ( Error 725 , Line 29 , Col 3 , Line 29 , Col 13 , " This union case does not take arguments" )
369
+ ( Warning 3548 , Line 32 , Col 3 , Line 32 , Col 9 , " Pattern discard is not allowed for union case that takes no data." )
370
+ ( Error 725 , Line 35 , Col 3 , Line 35 , Col 9 , " This union case does not take arguments" )
371
+ ( Error 725 , Line 38 , Col 3 , Line 38 , Col 14 , " This union case does not take arguments" )
372
+ ( Error 725 , Line 42 , Col 3 , Line 42 , Col 11 , " This union case does not take arguments" )
373
+ ( Error 725 , Line 48 , Col 3 , Line 48 , Col 8 , " This union case does not take arguments" )
374
+ ( Error 725 , Line 51 , Col 3 , Line 51 , Col 7 , " This union case does not take arguments" )
375
+ ( Warning 3548 , Line 53 , Col 24 , Line 53 , Col 27 , " Pattern discard is not allowed for union case that takes no data." )
376
+ ( Error 725 , Line 55 , Col 25 , Line 55 , Col 28 , " This union case does not take arguments" )
377
+ ( Error 725 , Line 57 , Col 25 , Line 57 , Col 29 , " This union case does not take arguments" )
378
+ ( Error 725 , Line 59 , Col 24 , Line 59 , Col 32 , " This union case does not take arguments" )
315
379
]
0 commit comments