-
Notifications
You must be signed in to change notification settings - Fork 867
Expand file tree
/
Copy pathCE_PipelineRange19550.fs
More file actions
278 lines (230 loc) · 6.99 KB
/
Copy pathCE_PipelineRange19550.fs
File metadata and controls
278 lines (230 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace Language
open Xunit
open FSharp.Test.Compiler
// https://github.com/dotnet/fsharp/issues/19550
module CE_PipelineRange19550 =
let private errorsOf (result: CompilationResult) : ErrorInfo list =
let diags =
match result with
| CompilationResult.Success r
| CompilationResult.Failure r -> r.Diagnostics
diags
|> List.filter (fun d ->
match d.Error with ErrorType.Error _ -> true | _ -> false)
let private dump (result: CompilationResult) : string =
errorsOf result
|> List.map (fun d ->
let n =
match d.Error with
| ErrorType.Error n
| ErrorType.Warning n
| ErrorType.Information n
| ErrorType.Hidden n -> n
sprintf " FS%04d (L%d,C%d)-(L%d,C%d): %s"
n d.Range.StartLine (d.Range.StartColumn + 1)
d.Range.EndLine (d.Range.EndColumn + 1) d.Message)
|> String.concat "\n"
let private hasDiagAt (code: int) (sLine, sCol, eLine, eCol) (result: CompilationResult) : CompilationResult =
let found =
errorsOf result
|> List.exists (fun d ->
(match d.Error with ErrorType.Error c -> c = code | _ -> false)
&& d.Range.StartLine = sLine
&& d.Range.StartColumn + 1 = sCol
&& d.Range.EndLine = eLine
&& d.Range.EndColumn + 1 = eCol)
if not found then
failwithf
"Expected diagnostic FS%04d at (Line %d, Col %d)-(Line %d, Col %d). Actual diagnostics:\n%s"
code sLine sCol eLine eCol (dump result)
result
let private hasNoRange0Error (result: CompilationResult) : CompilationResult =
let bad =
errorsOf result
|> List.filter (fun d ->
d.Range.StartLine = 1 && d.Range.StartColumn = 0
&& d.Range.EndLine = 1 && d.Range.EndColumn = 0)
if not (List.isEmpty bad) then
failwithf
"Unexpected range0 / unknown(1,1) error diagnostic. All diagnostics:\n%s"
(dump result)
result
[<Fact>]
let ``Issue 19550 - empty CE body in pipeline reports source range``() =
FSharp """
module Repro19550_01
type FooBuilder() =
member _.Zero() = fun x -> x + 42
let foo = FooBuilder()
"" |> foo {} |> printfn "%d"
"""
|> compile
|> shouldFail
|> hasDiagAt 193 (8, 7, 8, 13)
[<Fact>]
let ``Issue 19550 - single pipe with empty CE body has non-zero range``() =
FSharp """
module Repro19550_02
type FooBuilder() =
member _.Zero() = fun x -> x + 42
let foo = FooBuilder()
foo {} |> printfn "%d"
"""
|> compile
|> shouldFail
|> hasNoRange0Error
[<Fact>]
let ``Issue 19550 - empty CE body as function argument``() =
FSharp """
module Repro19550_03
type FooBuilder() =
member _.Zero() = fun x -> x + 42
let foo = FooBuilder()
let take (x: int) = x
let _ = take (foo {})
"""
|> compile
|> shouldFail
|> hasDiagAt 193 (9, 15, 9, 21)
[<Fact>]
let ``Issue 19550 - explicit type annotation mismatch on empty CE body``() =
FSharp """
module Repro19550_04
type FooBuilder() =
member _.Zero() = fun x -> x + 42
let foo = FooBuilder()
let x : int = foo {}
"""
|> compile
|> shouldFail
|> hasDiagAt 193 (8, 15, 8, 21)
[<Fact>]
let ``Issue 19550 - Yield builder in pipeline keeps non-zero range``() =
FSharp """
module Repro19550_05a
type YBuilder() =
member _.Yield(x) = fun y -> x + y
let yb = YBuilder()
"" |> yb { yield 1 } |> printfn "%d"
"""
|> compile
|> shouldFail
|> hasNoRange0Error
[<Fact>]
let ``Issue 19550 - Return builder in pipeline keeps non-zero range``() =
FSharp """
module Repro19550_05b
type RBuilder() =
member _.Return(x) = fun y -> x + y
let rb = RBuilder()
"" |> rb { return 1 } |> printfn "%d"
"""
|> compile
|> shouldFail
|> hasNoRange0Error
[<Fact>]
let ``Issue 19550 - Bind builder in pipeline keeps non-zero range``() =
FSharp """
module Repro19550_05c
type BBuilder() =
member _.Bind(x, f) = f x
member _.Return(x) = fun y -> x + y
let bb = BBuilder()
"" |> bb { let! x = 1 in return x } |> printfn "%d"
"""
|> compile
|> shouldFail
|> hasNoRange0Error
[<Fact>]
let ``Issue 19550 - nested CE - inner empty body in pipeline``() =
FSharp """
module Repro19550_06
type FooBuilder() =
member _.Zero() = fun x -> x + 42
let foo = FooBuilder()
type Outer() =
member _.Yield(_) : unit = ()
member _.Combine(_, _) = ()
member _.Delay(f: unit -> unit) = f ()
member _.Zero() = ()
let outer = Outer()
let _ = outer { do "" |> foo {} |> ignore }
"""
|> compile
|> shouldFail
|> hasDiagAt 193 (16, 26, 16, 32)
[<Fact>]
let ``Issue 19550 - valid empty CE body without type mismatch still compiles``() =
FSharp """
module Repro19550_07
type IdBuilder() =
member _.Zero() = 0
let id1 = IdBuilder()
let v : int = id1 {}
"""
|> compile
|> shouldSucceed
|> ignore
[<Fact>]
let ``Issue 19550 - non-pipeline empty CE body reports source range``() =
FSharp """
module Repro19550_08
type FooBuilder() =
member _.Zero() = fun x -> x + 42
let foo = FooBuilder()
let f : string -> string = foo {}
"""
|> compile
|> shouldFail
|> hasDiagAt 193 (8, 28, 8, 34)
[<Fact>]
let ``Issue 19550 - non-CE pipeline mismatch keeps non-zero range``() =
FSharp """
module Repro19550_09
let _ = "" |> (fun (x: int) -> x) |> printfn "%d"
"""
|> compile
|> shouldFail
|> hasNoRange0Error
[<Fact>]
let ``Issue 19550 - multi-line empty CE body in pipeline``() =
FSharp """
module Repro19550_10
type FooBuilder() =
member _.Zero() = fun x -> x + 42
let foo = FooBuilder()
"" |>
foo {
} |>
printfn "%d"
"""
|> compile
|> shouldFail
|> hasDiagAt 193 (9, 4, 10, 5)
[<Fact>]
let ``Issue 19550 - empty CE body in match arm pipeline``() =
FSharp """
module Repro19550_11
type FooBuilder() =
member _.Zero() = fun x -> x + 42
let foo = FooBuilder()
let r = match 0 with
| _ -> "" |> foo {} |> printfn "%d"
"""
|> compile
|> shouldFail
|> hasDiagAt 193 (9, 22, 9, 28)
[<Fact>]
let ``Issue 19550 - both Zero and Yield - empty body picks Zero path``() =
FSharp """
module Repro19550_12
type BothBuilder() =
member _.Zero() = fun x -> x + 1
member _.Yield(x) = fun y -> x + y
let bb = BothBuilder()
"" |> bb {} |> printfn "%d"
"""
|> compile
|> shouldFail
|> hasDiagAt 193 (9, 7, 9, 12)