microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.25.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/compiler/qsc_frontend/src/lower/tests.rs

2952lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use crate::compile::{self, PackageStore, compile};
5use expect_test::{Expect, expect};
6use indoc::indoc;
7use qsc_data_structures::{
8 language_features::LanguageFeatures, source::SourceMap, target::TargetCapabilityFlags,
9};
10
11fn check_hir(input: &str, expect: &Expect) {
12 let sources = SourceMap::new([("test".into(), input.into())], None);
13 let unit = compile(
14 &PackageStore::new(compile::core()),
15 &[],
16 sources,
17 TargetCapabilityFlags::all(),
18 LanguageFeatures::default(),
19 );
20 expect.assert_eq(&unit.package.to_string());
21}
22
23fn check_errors(input: &str, expect: &Expect) {
24 let sources = SourceMap::new([("test".into(), input.into())], None);
25 let unit = compile(
26 &PackageStore::new(compile::core()),
27 &[],
28 sources,
29 TargetCapabilityFlags::all(),
30 LanguageFeatures::default(),
31 );
32
33 let lower_errors: Vec<_> = unit
34 .errors
35 .into_iter()
36 .filter_map(try_into_lower_error)
37 .collect();
38
39 expect.assert_debug_eq(&lower_errors);
40}
41
42fn try_into_lower_error(error: compile::Error) -> Option<super::Error> {
43 if let compile::ErrorKind::Lower(error) = error.0 {
44 Some(error)
45 } else {
46 None
47 }
48}
49
50#[test]
51fn test_entrypoint_attr_allowed() {
52 check_errors(
53 indoc! {"
54 namespace input {
55 @EntryPoint()
56 operation Foo() : Unit {
57 body ... {}
58 }
59 }
60 "},
61 &expect![[r#"
62 []
63 "#]],
64 );
65}
66
67#[test]
68fn test_entrypoint_attr_wrong_args() {
69 check_errors(
70 indoc! {r#"
71 namespace input {
72 @EntryPoint("Bar")
73 operation Foo() : Unit {
74 body ... {}
75 }
76 }
77 "#},
78 &expect![[r#"
79 [
80 InvalidAttrArgs(
81 "empty or profile name",
82 Span {
83 lo: 33,
84 hi: 40,
85 },
86 ),
87 ]
88 "#]],
89 );
90}
91
92#[test]
93fn test_target_profile_base_attr_allowed() {
94 check_errors(
95 indoc! {"
96 namespace input {
97 @Config(Base)
98 operation Foo() : Unit {
99 body ... {}
100 }
101 }
102 "},
103 &expect![[r#"
104 []
105 "#]],
106 );
107}
108
109#[test]
110fn test_target_profile_attr_wrong_args() {
111 check_errors(
112 indoc! {"
113 namespace input {
114 @Config(Bar)
115 operation Foo() : Unit {
116 body ... {}
117 }
118 }
119 "},
120 &expect![[r#"
121 [
122 InvalidAttrArgs(
123 "runtime capability",
124 Span {
125 lo: 29,
126 hi: 34,
127 },
128 ),
129 ]
130 "#]],
131 );
132}
133
134#[test]
135fn test_unknown_attr() {
136 check_errors(
137 indoc! {"
138 namespace input {
139 @Bar()
140 operation Foo() : Unit {
141 body ... {}
142 }
143 }
144 "},
145 &expect![[r#"
146 [
147 UnknownAttr(
148 "Bar",
149 Span {
150 lo: 23,
151 hi: 26,
152 },
153 ),
154 ]
155 "#]],
156 );
157}
158
159#[test]
160fn lift_local_function() {
161 check_hir(
162 indoc! {"
163 namespace A {
164 function Foo(x : Int) : Int {
165 function Bar(y : Int) : Int { y + 1 }
166 Bar(x + 2)
167 }
168 }
169 "},
170 &expect![[r#"
171 Package:
172 Item 0 [0-120] (Public):
173 Namespace (Ident 23 [10-11] "A"): Item 1
174 Item 1 [18-118] (Internal):
175 Parent: 0
176 Callable 0 [18-118] (function):
177 name: Ident 1 [27-30] "Foo"
178 input: Pat 2 [31-38] [Type Int]: Bind: Ident 3 [31-32] "x"
179 output: Int
180 functors: empty set
181 body: SpecDecl 4 [18-118]: Impl:
182 Block 5 [46-118] [Type Int]:
183 Stmt 6 [56-93]: Item: 2
184 Stmt 17 [102-112]: Expr: Expr 18 [102-112] [Type Int]: Call:
185 Expr 19 [102-105] [Type (Int -> Int)]: Var: Item 2 (Package 1)
186 Expr 20 [106-111] [Type Int]: BinOp (Add):
187 Expr 21 [106-107] [Type Int]: Var: Local 3
188 Expr 22 [110-111] [Type Int]: Lit: Int(2)
189 adj: <none>
190 ctl: <none>
191 ctl-adj: <none>
192 Item 2 [56-93] (Internal):
193 Parent: 1
194 Callable 7 [56-93] (function):
195 name: Ident 8 [65-68] "Bar"
196 input: Pat 9 [69-76] [Type Int]: Bind: Ident 10 [69-70] "y"
197 output: Int
198 functors: empty set
199 body: SpecDecl 11 [56-93]: Impl:
200 Block 12 [84-93] [Type Int]:
201 Stmt 13 [86-91]: Expr: Expr 14 [86-91] [Type Int]: BinOp (Add):
202 Expr 15 [86-87] [Type Int]: Var: Local 10
203 Expr 16 [90-91] [Type Int]: Lit: Int(1)
204 adj: <none>
205 ctl: <none>
206 ctl-adj: <none>"#]],
207 );
208}
209
210#[test]
211fn lift_local_operation() {
212 check_hir(
213 indoc! {"
214 namespace A {
215 operation Foo() : Result {
216 operation Bar(q : Qubit) : Result { Zero }
217 use q = Qubit();
218 Bar(q)
219 }
220 }
221 "},
222 &expect![[r#"
223 Package:
224 Item 0 [0-143] (Public):
225 Namespace (Ident 22 [10-11] "A"): Item 1
226 Item 1 [18-141] (Internal):
227 Parent: 0
228 Callable 0 [18-141] (operation):
229 name: Ident 1 [28-31] "Foo"
230 input: Pat 2 [31-33] [Type Unit]: Unit
231 output: Result
232 functors: empty set
233 body: SpecDecl 3 [18-141]: Impl:
234 Block 4 [43-141] [Type Result]:
235 Stmt 5 [53-95]: Item: 2
236 Stmt 14 [104-120]: Qubit (Fresh)
237 Pat 15 [108-109] [Type Qubit]: Bind: Ident 16 [108-109] "q"
238 QubitInit 17 [112-119] [Type Qubit]: Single
239 Stmt 18 [129-135]: Expr: Expr 19 [129-135] [Type Result]: Call:
240 Expr 20 [129-132] [Type (Qubit => Result)]: Var: Item 2 (Package 1)
241 Expr 21 [133-134] [Type Qubit]: Var: Local 16
242 adj: <none>
243 ctl: <none>
244 ctl-adj: <none>
245 Item 2 [53-95] (Internal):
246 Parent: 1
247 Callable 6 [53-95] (operation):
248 name: Ident 7 [63-66] "Bar"
249 input: Pat 8 [67-76] [Type Qubit]: Bind: Ident 9 [67-68] "q"
250 output: Result
251 functors: empty set
252 body: SpecDecl 10 [53-95]: Impl:
253 Block 11 [87-95] [Type Result]:
254 Stmt 12 [89-93]: Expr: Expr 13 [89-93] [Type Result]: Lit: Result(Zero)
255 adj: <none>
256 ctl: <none>
257 ctl-adj: <none>"#]],
258 );
259}
260
261#[test]
262fn lift_local_newtype() {
263 check_hir(
264 indoc! {"
265 namespace A {
266 function Foo() : Int {
267 newtype Bar = Int;
268 let x = Bar(5);
269 x!
270 }
271 }
272 "},
273 &expect![[r#"
274 Package:
275 Item 0 [0-110] (Public):
276 Namespace (Ident 16 [10-11] "A"): Item 1
277 Item 1 [18-108] (Internal):
278 Parent: 0
279 Callable 0 [18-108] (function):
280 name: Ident 1 [27-30] "Foo"
281 input: Pat 2 [30-32] [Type Unit]: Unit
282 output: Int
283 functors: empty set
284 body: SpecDecl 3 [18-108]: Impl:
285 Block 4 [39-108] [Type Int]:
286 Stmt 5 [49-67]: Item: 2
287 Stmt 7 [76-91]: Local (Immutable):
288 Pat 8 [80-81] [Type UDT<"Bar": Item 2 (Package 1)>]: Bind: Ident 9 [80-81] "x"
289 Expr 10 [84-90] [Type UDT<"Bar": Item 2 (Package 1)>]: Call:
290 Expr 11 [84-87] [Type (Int -> UDT<"Bar": Item 2 (Package 1)>)]: Var: Item 2 (Package 1)
291 Expr 12 [88-89] [Type Int]: Lit: Int(5)
292 Stmt 13 [100-102]: Expr: Expr 14 [100-102] [Type Int]: UnOp (Unwrap):
293 Expr 15 [100-101] [Type UDT<"Bar": Item 2 (Package 1)>]: Var: Local 9
294 adj: <none>
295 ctl: <none>
296 ctl-adj: <none>
297 Item 2 [49-67] (Internal):
298 Parent: 1
299 Type (Ident 6 [57-60] "Bar"): UDT [49-67]:
300 TyDef [63-66]: Field:
301 type: Int"#]],
302 );
303}
304
305#[test]
306fn lift_newtype() {
307 check_hir(
308 indoc! {"
309 namespace A {
310 newtype Foo = Int;
311 operation Bar() : Unit {
312 let x = Foo(1);
313 }
314 }
315 "},
316 &expect![[r#"
317 Package:
318 Item 0 [0-97] (Public):
319 Namespace (Ident 12 [10-11] "A"): Item 1, Item 2
320 Item 1 [18-36] (Internal):
321 Parent: 0
322 Type (Ident 0 [26-29] "Foo"): UDT [18-36]:
323 TyDef [32-35]: Field:
324 type: Int
325 Item 2 [41-95] (Internal):
326 Parent: 0
327 Callable 1 [41-95] (operation):
328 name: Ident 2 [51-54] "Bar"
329 input: Pat 3 [54-56] [Type Unit]: Unit
330 output: Unit
331 functors: empty set
332 body: SpecDecl 4 [41-95]: Impl:
333 Block 5 [64-95] [Type Unit]:
334 Stmt 6 [74-89]: Local (Immutable):
335 Pat 7 [78-79] [Type UDT<"Foo": Item 1 (Package 1)>]: Bind: Ident 8 [78-79] "x"
336 Expr 9 [82-88] [Type UDT<"Foo": Item 1 (Package 1)>]: Call:
337 Expr 10 [82-85] [Type (Int -> UDT<"Foo": Item 1 (Package 1)>)]: Var: Item 1 (Package 1)
338 Expr 11 [86-87] [Type Int]: Lit: Int(1)
339 adj: <none>
340 ctl: <none>
341 ctl-adj: <none>"#]],
342 );
343}
344
345#[test]
346fn lift_newtype_tuple() {
347 check_hir(
348 indoc! {"
349 namespace A {
350 newtype Foo = (Int, Double);
351 operation Bar() : Unit {
352 let x = Foo(1, 2.3);
353 }
354 }
355 "},
356 &expect![[r#"
357 Package:
358 Item 0 [0-112] (Public):
359 Namespace (Ident 14 [10-11] "A"): Item 1, Item 2
360 Item 1 [18-46] (Internal):
361 Parent: 0
362 Type (Ident 0 [26-29] "Foo"): UDT [18-46]:
363 TyDef [32-45]: Field:
364 type: (Int, Double)
365 Item 2 [51-110] (Internal):
366 Parent: 0
367 Callable 1 [51-110] (operation):
368 name: Ident 2 [61-64] "Bar"
369 input: Pat 3 [64-66] [Type Unit]: Unit
370 output: Unit
371 functors: empty set
372 body: SpecDecl 4 [51-110]: Impl:
373 Block 5 [74-110] [Type Unit]:
374 Stmt 6 [84-104]: Local (Immutable):
375 Pat 7 [88-89] [Type UDT<"Foo": Item 1 (Package 1)>]: Bind: Ident 8 [88-89] "x"
376 Expr 9 [92-103] [Type UDT<"Foo": Item 1 (Package 1)>]: Call:
377 Expr 10 [92-95] [Type ((Int, Double) -> UDT<"Foo": Item 1 (Package 1)>)]: Var: Item 1 (Package 1)
378 Expr 11 [95-103] [Type (Int, Double)]: Tuple:
379 Expr 12 [96-97] [Type Int]: Lit: Int(1)
380 Expr 13 [99-102] [Type Double]: Lit: Double(2.3)
381 adj: <none>
382 ctl: <none>
383 ctl-adj: <none>"#]],
384 );
385}
386
387#[test]
388fn lift_newtype_tuple_fields() {
389 check_hir(
390 indoc! {"
391 namespace A {
392 newtype Foo = (a: Int, b: Double);
393 operation Bar() : Unit {
394 let x = Foo(1, 2.3);
395 let y = x::b;
396 }
397 }
398 "},
399 &expect![[r#"
400 Package:
401 Item 0 [0-140] (Public):
402 Namespace (Ident 19 [10-11] "A"): Item 1, Item 2
403 Item 1 [18-52] (Internal):
404 Parent: 0
405 Type (Ident 0 [26-29] "Foo"): UDT [18-52]:
406 TyDef [32-51]: Tuple:
407 TyDef [33-39]: Field:
408 name: a [33-34]
409 type: Int
410 TyDef [41-50]: Field:
411 name: b [41-42]
412 type: Double
413 Item 2 [57-138] (Internal):
414 Parent: 0
415 Callable 1 [57-138] (operation):
416 name: Ident 2 [67-70] "Bar"
417 input: Pat 3 [70-72] [Type Unit]: Unit
418 output: Unit
419 functors: empty set
420 body: SpecDecl 4 [57-138]: Impl:
421 Block 5 [80-138] [Type Unit]:
422 Stmt 6 [90-110]: Local (Immutable):
423 Pat 7 [94-95] [Type UDT<"Foo": Item 1 (Package 1)>]: Bind: Ident 8 [94-95] "x"
424 Expr 9 [98-109] [Type UDT<"Foo": Item 1 (Package 1)>]: Call:
425 Expr 10 [98-101] [Type ((Int, Double) -> UDT<"Foo": Item 1 (Package 1)>)]: Var: Item 1 (Package 1)
426 Expr 11 [101-109] [Type (Int, Double)]: Tuple:
427 Expr 12 [102-103] [Type Int]: Lit: Int(1)
428 Expr 13 [105-108] [Type Double]: Lit: Double(2.3)
429 Stmt 14 [119-132]: Local (Immutable):
430 Pat 15 [123-124] [Type Double]: Bind: Ident 16 [123-124] "y"
431 Expr 17 [127-131] [Type Double]: Field:
432 Expr 18 [127-128] [Type UDT<"Foo": Item 1 (Package 1)>]: Var: Local 8
433 Path(FieldPath { indices: [1] })
434 adj: <none>
435 ctl: <none>
436 ctl-adj: <none>"#]],
437 );
438}
439
440#[test]
441fn lift_newtype_nested_tuple() {
442 check_hir(
443 indoc! {"
444 namespace A {
445 newtype Foo = (Int, (Double, Bool));
446 operation Bar() : Unit {
447 let x = Foo(1, (2.3, true));
448 }
449 }
450 "},
451 &expect![[r#"
452 Package:
453 Item 0 [0-128] (Public):
454 Namespace (Ident 16 [10-11] "A"): Item 1, Item 2
455 Item 1 [18-54] (Internal):
456 Parent: 0
457 Type (Ident 0 [26-29] "Foo"): UDT [18-54]:
458 TyDef [32-53]: Field:
459 type: (Int, (Double, Bool))
460 Item 2 [59-126] (Internal):
461 Parent: 0
462 Callable 1 [59-126] (operation):
463 name: Ident 2 [69-72] "Bar"
464 input: Pat 3 [72-74] [Type Unit]: Unit
465 output: Unit
466 functors: empty set
467 body: SpecDecl 4 [59-126]: Impl:
468 Block 5 [82-126] [Type Unit]:
469 Stmt 6 [92-120]: Local (Immutable):
470 Pat 7 [96-97] [Type UDT<"Foo": Item 1 (Package 1)>]: Bind: Ident 8 [96-97] "x"
471 Expr 9 [100-119] [Type UDT<"Foo": Item 1 (Package 1)>]: Call:
472 Expr 10 [100-103] [Type ((Int, (Double, Bool)) -> UDT<"Foo": Item 1 (Package 1)>)]: Var: Item 1 (Package 1)
473 Expr 11 [103-119] [Type (Int, (Double, Bool))]: Tuple:
474 Expr 12 [104-105] [Type Int]: Lit: Int(1)
475 Expr 13 [107-118] [Type (Double, Bool)]: Tuple:
476 Expr 14 [108-111] [Type Double]: Lit: Double(2.3)
477 Expr 15 [113-117] [Type Bool]: Lit: Bool(true)
478 adj: <none>
479 ctl: <none>
480 ctl-adj: <none>"#]],
481 );
482}
483
484#[test]
485fn lift_newtype_nested_tuple_fields() {
486 check_hir(
487 indoc! {"
488 namespace A {
489 newtype Foo = (a: Int, (b: Double, c: Bool));
490 operation Bar() : Unit {
491 let x = Foo(1, (2.3, true));
492 let y = x::c;
493 }
494 }
495 "},
496 &expect![[r#"
497 Package:
498 Item 0 [0-159] (Public):
499 Namespace (Ident 21 [10-11] "A"): Item 1, Item 2
500 Item 1 [18-63] (Internal):
501 Parent: 0
502 Type (Ident 0 [26-29] "Foo"): UDT [18-63]:
503 TyDef [32-62]: Tuple:
504 TyDef [33-39]: Field:
505 name: a [33-34]
506 type: Int
507 TyDef [41-61]: Tuple:
508 TyDef [42-51]: Field:
509 name: b [42-43]
510 type: Double
511 TyDef [53-60]: Field:
512 name: c [53-54]
513 type: Bool
514 Item 2 [68-157] (Internal):
515 Parent: 0
516 Callable 1 [68-157] (operation):
517 name: Ident 2 [78-81] "Bar"
518 input: Pat 3 [81-83] [Type Unit]: Unit
519 output: Unit
520 functors: empty set
521 body: SpecDecl 4 [68-157]: Impl:
522 Block 5 [91-157] [Type Unit]:
523 Stmt 6 [101-129]: Local (Immutable):
524 Pat 7 [105-106] [Type UDT<"Foo": Item 1 (Package 1)>]: Bind: Ident 8 [105-106] "x"
525 Expr 9 [109-128] [Type UDT<"Foo": Item 1 (Package 1)>]: Call:
526 Expr 10 [109-112] [Type ((Int, (Double, Bool)) -> UDT<"Foo": Item 1 (Package 1)>)]: Var: Item 1 (Package 1)
527 Expr 11 [112-128] [Type (Int, (Double, Bool))]: Tuple:
528 Expr 12 [113-114] [Type Int]: Lit: Int(1)
529 Expr 13 [116-127] [Type (Double, Bool)]: Tuple:
530 Expr 14 [117-120] [Type Double]: Lit: Double(2.3)
531 Expr 15 [122-126] [Type Bool]: Lit: Bool(true)
532 Stmt 16 [138-151]: Local (Immutable):
533 Pat 17 [142-143] [Type Bool]: Bind: Ident 18 [142-143] "y"
534 Expr 19 [146-150] [Type Bool]: Field:
535 Expr 20 [146-147] [Type UDT<"Foo": Item 1 (Package 1)>]: Var: Local 8
536 Path(FieldPath { indices: [1, 1] })
537 adj: <none>
538 ctl: <none>
539 ctl-adj: <none>"#]],
540 );
541}
542
543#[test]
544fn lift_newtype_from_newtype() {
545 check_hir(
546 indoc! {"
547 namespace A {
548 newtype Foo = (a: Int, (b: Double, c: Bool));
549 newtype Bar = (x: Int, y: Foo);
550 operation Baz() : Unit {
551 let x = Bar(1, Foo(2, (3.4, false)));
552 let y = x::y::c;
553 }
554 }
555 "},
556 &expect![[r#"
557 Package:
558 Item 0 [0-207] (Public):
559 Namespace (Ident 27 [10-11] "A"): Item 1, Item 2, Item 3
560 Item 1 [18-63] (Internal):
561 Parent: 0
562 Type (Ident 0 [26-29] "Foo"): UDT [18-63]:
563 TyDef [32-62]: Tuple:
564 TyDef [33-39]: Field:
565 name: a [33-34]
566 type: Int
567 TyDef [41-61]: Tuple:
568 TyDef [42-51]: Field:
569 name: b [42-43]
570 type: Double
571 TyDef [53-60]: Field:
572 name: c [53-54]
573 type: Bool
574 Item 2 [68-99] (Internal):
575 Parent: 0
576 Type (Ident 1 [76-79] "Bar"): UDT [68-99]:
577 TyDef [82-98]: Tuple:
578 TyDef [83-89]: Field:
579 name: x [83-84]
580 type: Int
581 TyDef [91-97]: Field:
582 name: y [91-92]
583 type: UDT<"Foo": Item 1 (Package 1)>
584 Item 3 [104-205] (Internal):
585 Parent: 0
586 Callable 2 [104-205] (operation):
587 name: Ident 3 [114-117] "Baz"
588 input: Pat 4 [117-119] [Type Unit]: Unit
589 output: Unit
590 functors: empty set
591 body: SpecDecl 5 [104-205]: Impl:
592 Block 6 [127-205] [Type Unit]:
593 Stmt 7 [137-174]: Local (Immutable):
594 Pat 8 [141-142] [Type UDT<"Bar": Item 2 (Package 1)>]: Bind: Ident 9 [141-142] "x"
595 Expr 10 [145-173] [Type UDT<"Bar": Item 2 (Package 1)>]: Call:
596 Expr 11 [145-148] [Type ((Int, UDT<"Foo": Item 1 (Package 1)>) -> UDT<"Bar": Item 2 (Package 1)>)]: Var: Item 2 (Package 1)
597 Expr 12 [148-173] [Type (Int, UDT<"Foo": Item 1 (Package 1)>)]: Tuple:
598 Expr 13 [149-150] [Type Int]: Lit: Int(1)
599 Expr 14 [152-172] [Type UDT<"Foo": Item 1 (Package 1)>]: Call:
600 Expr 15 [152-155] [Type ((Int, (Double, Bool)) -> UDT<"Foo": Item 1 (Package 1)>)]: Var: Item 1 (Package 1)
601 Expr 16 [155-172] [Type (Int, (Double, Bool))]: Tuple:
602 Expr 17 [156-157] [Type Int]: Lit: Int(2)
603 Expr 18 [159-171] [Type (Double, Bool)]: Tuple:
604 Expr 19 [160-163] [Type Double]: Lit: Double(3.4)
605 Expr 20 [165-170] [Type Bool]: Lit: Bool(false)
606 Stmt 21 [183-199]: Local (Immutable):
607 Pat 22 [187-188] [Type Bool]: Bind: Ident 23 [187-188] "y"
608 Expr 24 [191-198] [Type Bool]: Field:
609 Expr 25 [191-195] [Type UDT<"Foo": Item 1 (Package 1)>]: Field:
610 Expr 26 [191-192] [Type UDT<"Bar": Item 2 (Package 1)>]: Var: Local 9
611 Path(FieldPath { indices: [1] })
612 Path(FieldPath { indices: [1, 1] })
613 adj: <none>
614 ctl: <none>
615 ctl-adj: <none>"#]],
616 );
617}
618
619#[test]
620fn lower_struct_decl() {
621 check_hir(
622 indoc! {"
623 namespace A {
624 struct Foo {
625 x: Int,
626 y: Double,
627 }
628 }
629 "},
630 &expect![[r#"
631 Package:
632 Item 0 [0-73] (Public):
633 Namespace (Ident 1 [10-11] "A"): Item 1
634 Item 1 [18-71] (Internal):
635 Parent: 0
636 Type (Ident 0 [25-28] "Foo"): UDT [18-71]:
637 TyDef [18-71]: Tuple:
638 TyDef [39-45]: Field:
639 name: x [39-40]
640 type: Int
641 TyDef [55-64]: Field:
642 name: y [55-56]
643 type: Double"#]],
644 );
645}
646
647#[test]
648fn lower_struct_constructor() {
649 check_hir(
650 indoc! {"
651 namespace A {
652 struct Foo {
653 x: Int,
654 y: Double,
655 }
656 operation Bar() : Unit {
657 let z = new Foo { x = 1, y = 2.3 };
658 }
659 }
660 "},
661 &expect![[r#"
662 Package:
663 Item 0 [0-152] (Public):
664 Namespace (Ident 14 [10-11] "A"): Item 1, Item 2
665 Item 1 [18-71] (Internal):
666 Parent: 0
667 Type (Ident 0 [25-28] "Foo"): UDT [18-71]:
668 TyDef [18-71]: Tuple:
669 TyDef [39-45]: Field:
670 name: x [39-40]
671 type: Int
672 TyDef [55-64]: Field:
673 name: y [55-56]
674 type: Double
675 Item 2 [76-150] (Internal):
676 Parent: 0
677 Callable 1 [76-150] (operation):
678 name: Ident 2 [86-89] "Bar"
679 input: Pat 3 [89-91] [Type Unit]: Unit
680 output: Unit
681 functors: empty set
682 body: SpecDecl 4 [76-150]: Impl:
683 Block 5 [99-150] [Type Unit]:
684 Stmt 6 [109-144]: Local (Immutable):
685 Pat 7 [113-114] [Type UDT<"Foo": Item 1 (Package 1)>]: Bind: Ident 8 [113-114] "z"
686 Expr 9 [117-143] [Type UDT<"Foo": Item 1 (Package 1)>]: Struct (Item 1 (Package 1)):
687 FieldsAssign 10 [127-132]: (Path([0])) Expr 11 [131-132] [Type Int]: Lit: Int(1)
688 FieldsAssign 12 [134-141]: (Path([1])) Expr 13 [138-141] [Type Double]: Lit: Double(2.3)
689 adj: <none>
690 ctl: <none>
691 ctl-adj: <none>"#]],
692 );
693}
694
695#[test]
696fn lower_struct_copy_constructor() {
697 check_hir(
698 indoc! {"
699 namespace A {
700 struct Foo {
701 x: Int,
702 y: Double,
703 }
704 operation Bar() : Foo {
705 let z = new Foo { x = 1, y = 2.3 };
706 new Foo { ...z, x = 4 };
707 }
708 }
709 "},
710 &expect![[r#"
711 Package:
712 Item 0 [0-184] (Public):
713 Namespace (Ident 19 [10-11] "A"): Item 1, Item 2
714 Item 1 [18-71] (Internal):
715 Parent: 0
716 Type (Ident 0 [25-28] "Foo"): UDT [18-71]:
717 TyDef [18-71]: Tuple:
718 TyDef [39-45]: Field:
719 name: x [39-40]
720 type: Int
721 TyDef [55-64]: Field:
722 name: y [55-56]
723 type: Double
724 Item 2 [76-182] (Internal):
725 Parent: 0
726 Callable 1 [76-182] (operation):
727 name: Ident 2 [86-89] "Bar"
728 input: Pat 3 [89-91] [Type Unit]: Unit
729 output: UDT<"Foo": Item 1 (Package 1)>
730 functors: empty set
731 body: SpecDecl 4 [76-182]: Impl:
732 Block 5 [98-182] [Type Unit]:
733 Stmt 6 [108-143]: Local (Immutable):
734 Pat 7 [112-113] [Type UDT<"Foo": Item 1 (Package 1)>]: Bind: Ident 8 [112-113] "z"
735 Expr 9 [116-142] [Type UDT<"Foo": Item 1 (Package 1)>]: Struct (Item 1 (Package 1)):
736 FieldsAssign 10 [126-131]: (Path([0])) Expr 11 [130-131] [Type Int]: Lit: Int(1)
737 FieldsAssign 12 [133-140]: (Path([1])) Expr 13 [137-140] [Type Double]: Lit: Double(2.3)
738 Stmt 14 [152-176]: Semi: Expr 15 [152-175] [Type UDT<"Foo": Item 1 (Package 1)>]: Struct (Item 1 (Package 1)):
739 Copy: Expr 16 [165-166] [Type UDT<"Foo": Item 1 (Package 1)>]: Var: Local 8
740 FieldsAssign 17 [168-173]: (Path([0])) Expr 18 [172-173] [Type Int]: Lit: Int(4)
741 adj: <none>
742 ctl: <none>
743 ctl-adj: <none>"#]],
744 );
745}
746
747#[test]
748fn lower_struct_copy_constructor_with_alternative_fields() {
749 check_hir(
750 indoc! {r#"
751 namespace A {
752 struct Foo {
753 x: Int,
754 y: Double,
755 z: String
756 }
757 operation Bar() : Foo {
758 let z = new Foo { x = 1, y = 2.3, z = "four" };
759 new Foo { ...z, z = "five", y = 6.7 };
760 }
761 }
762 "#},
763 &expect![[r#"
764 Package:
765 Item 0 [0-228] (Public):
766 Namespace (Ident 23 [10-11] "A"): Item 1, Item 2
767 Item 1 [18-89] (Internal):
768 Parent: 0
769 Type (Ident 0 [25-28] "Foo"): UDT [18-89]:
770 TyDef [18-89]: Tuple:
771 TyDef [39-45]: Field:
772 name: x [39-40]
773 type: Int
774 TyDef [55-64]: Field:
775 name: y [55-56]
776 type: Double
777 TyDef [74-83]: Field:
778 name: z [74-75]
779 type: String
780 Item 2 [94-226] (Internal):
781 Parent: 0
782 Callable 1 [94-226] (operation):
783 name: Ident 2 [104-107] "Bar"
784 input: Pat 3 [107-109] [Type Unit]: Unit
785 output: UDT<"Foo": Item 1 (Package 1)>
786 functors: empty set
787 body: SpecDecl 4 [94-226]: Impl:
788 Block 5 [116-226] [Type Unit]:
789 Stmt 6 [126-173]: Local (Immutable):
790 Pat 7 [130-131] [Type UDT<"Foo": Item 1 (Package 1)>]: Bind: Ident 8 [130-131] "z"
791 Expr 9 [134-172] [Type UDT<"Foo": Item 1 (Package 1)>]: Struct (Item 1 (Package 1)):
792 FieldsAssign 10 [144-149]: (Path([0])) Expr 11 [148-149] [Type Int]: Lit: Int(1)
793 FieldsAssign 12 [151-158]: (Path([1])) Expr 13 [155-158] [Type Double]: Lit: Double(2.3)
794 FieldsAssign 14 [160-170]: (Path([2])) Expr 15 [164-170] [Type String]: String:
795 Lit: "four"
796 Stmt 16 [182-220]: Semi: Expr 17 [182-219] [Type UDT<"Foo": Item 1 (Package 1)>]: Struct (Item 1 (Package 1)):
797 Copy: Expr 18 [195-196] [Type UDT<"Foo": Item 1 (Package 1)>]: Var: Local 8
798 FieldsAssign 19 [198-208]: (Path([2])) Expr 20 [202-208] [Type String]: String:
799 Lit: "five"
800 FieldsAssign 21 [210-217]: (Path([1])) Expr 22 [214-217] [Type Double]: Lit: Double(6.7)
801 adj: <none>
802 ctl: <none>
803 ctl-adj: <none>"#]],
804 );
805}
806
807#[test]
808fn lower_fields_path() {
809 check_hir(
810 indoc! {r#"
811 namespace Foo {
812 struct A { b : B }
813 struct B { c : C }
814 struct C { i : Int }
815 operation Bar(a : A) : Unit {
816 let x = a.b.c.i;
817 }
818 }
819 "#},
820 &expect![[r#"
821 Package:
822 Item 0 [0-153] (Public):
823 Namespace (Ident 16 [10-13] "Foo"): Item 1, Item 2, Item 3, Item 4
824 Item 1 [20-38] (Internal):
825 Parent: 0
826 Type (Ident 0 [27-28] "A"): UDT [20-38]:
827 TyDef [20-38]: Tuple:
828 TyDef [31-36]: Field:
829 name: b [31-32]
830 type: UDT<"B": Item 2 (Package 1)>
831 Item 2 [43-61] (Internal):
832 Parent: 0
833 Type (Ident 1 [50-51] "B"): UDT [43-61]:
834 TyDef [43-61]: Tuple:
835 TyDef [54-59]: Field:
836 name: c [54-55]
837 type: UDT<"C": Item 3 (Package 1)>
838 Item 3 [66-86] (Internal):
839 Parent: 0
840 Type (Ident 2 [73-74] "C"): UDT [66-86]:
841 TyDef [66-86]: Tuple:
842 TyDef [77-84]: Field:
843 name: i [77-78]
844 type: Int
845 Item 4 [91-151] (Internal):
846 Parent: 0
847 Callable 3 [91-151] (operation):
848 name: Ident 4 [101-104] "Bar"
849 input: Pat 5 [105-110] [Type UDT<"A": Item 1 (Package 1)>]: Bind: Ident 6 [105-106] "a"
850 output: Unit
851 functors: empty set
852 body: SpecDecl 7 [91-151]: Impl:
853 Block 8 [119-151] [Type Unit]:
854 Stmt 9 [129-145]: Local (Immutable):
855 Pat 10 [133-134] [Type Int]: Bind: Ident 11 [133-134] "x"
856 Expr 12 [137-144] [Type Int]: Field:
857 Expr 15 [137-142] [Type UDT<"C": Item 3 (Package 1)>]: Field:
858 Expr 14 [137-140] [Type UDT<"B": Item 2 (Package 1)>]: Field:
859 Expr 13 [137-138] [Type UDT<"A": Item 1 (Package 1)>]: Var: Local 6
860 Path(FieldPath { indices: [0] })
861 Path(FieldPath { indices: [0] })
862 Path(FieldPath { indices: [0] })
863 adj: <none>
864 ctl: <none>
865 ctl-adj: <none>"#]],
866 );
867}
868
869#[test]
870fn lower_fields_path_with_expr() {
871 check_hir(
872 indoc! {r#"
873 namespace Foo {
874 struct A { b : B }
875 struct B { c : C }
876 struct C { i : Int }
877 operation Bar(a : A) : Unit {
878 let x = { a.b }.c.i;
879 }
880 }
881 "#},
882 &expect![[r#"
883 Package:
884 Item 0 [0-157] (Public):
885 Namespace (Ident 19 [10-13] "Foo"): Item 1, Item 2, Item 3, Item 4
886 Item 1 [20-38] (Internal):
887 Parent: 0
888 Type (Ident 0 [27-28] "A"): UDT [20-38]:
889 TyDef [20-38]: Tuple:
890 TyDef [31-36]: Field:
891 name: b [31-32]
892 type: UDT<"B": Item 2 (Package 1)>
893 Item 2 [43-61] (Internal):
894 Parent: 0
895 Type (Ident 1 [50-51] "B"): UDT [43-61]:
896 TyDef [43-61]: Tuple:
897 TyDef [54-59]: Field:
898 name: c [54-55]
899 type: UDT<"C": Item 3 (Package 1)>
900 Item 3 [66-86] (Internal):
901 Parent: 0
902 Type (Ident 2 [73-74] "C"): UDT [66-86]:
903 TyDef [66-86]: Tuple:
904 TyDef [77-84]: Field:
905 name: i [77-78]
906 type: Int
907 Item 4 [91-155] (Internal):
908 Parent: 0
909 Callable 3 [91-155] (operation):
910 name: Ident 4 [101-104] "Bar"
911 input: Pat 5 [105-110] [Type UDT<"A": Item 1 (Package 1)>]: Bind: Ident 6 [105-106] "a"
912 output: Unit
913 functors: empty set
914 body: SpecDecl 7 [91-155]: Impl:
915 Block 8 [119-155] [Type Unit]:
916 Stmt 9 [129-149]: Local (Immutable):
917 Pat 10 [133-134] [Type Int]: Bind: Ident 11 [133-134] "x"
918 Expr 12 [137-148] [Type Int]: Field:
919 Expr 13 [137-146] [Type UDT<"C": Item 3 (Package 1)>]: Field:
920 Expr 14 [137-144] [Type UDT<"B": Item 2 (Package 1)>]: Expr Block: Block 15 [137-144] [Type UDT<"B": Item 2 (Package 1)>]:
921 Stmt 16 [139-142]: Expr: Expr 17 [139-142] [Type UDT<"B": Item 2 (Package 1)>]: Field:
922 Expr 18 [139-140] [Type UDT<"A": Item 1 (Package 1)>]: Var: Local 6
923 Path(FieldPath { indices: [0] })
924 Path(FieldPath { indices: [0] })
925 Path(FieldPath { indices: [0] })
926 adj: <none>
927 ctl: <none>
928 ctl-adj: <none>"#]],
929 );
930}
931
932#[test]
933fn lambda_function_empty_closure() {
934 check_hir(
935 indoc! {"
936 namespace A {
937 function Foo() : Int {
938 let f = x -> x + 1;
939 f(1)
940 }
941 }
942 "},
943 &expect![[r#"
944 Package:
945 Item 0 [0-89] (Public):
946 Namespace (Ident 24 [10-11] "A"): Item 1
947 Item 1 [18-87] (Internal):
948 Parent: 0
949 Callable 0 [18-87] (function):
950 name: Ident 1 [27-30] "Foo"
951 input: Pat 2 [30-32] [Type Unit]: Unit
952 output: Int
953 functors: empty set
954 body: SpecDecl 3 [18-87]: Impl:
955 Block 4 [39-87] [Type Int]:
956 Stmt 5 [49-68]: Local (Immutable):
957 Pat 6 [53-54] [Type (Int -> Int)]: Bind: Ident 7 [53-54] "f"
958 Expr 8 [57-67] [Type (Int -> Int)]: Closure([], 2)
959 Stmt 20 [77-81]: Expr: Expr 21 [77-81] [Type Int]: Call:
960 Expr 22 [77-78] [Type (Int -> Int)]: Var: Local 7
961 Expr 23 [79-80] [Type Int]: Lit: Int(1)
962 adj: <none>
963 ctl: <none>
964 ctl-adj: <none>
965 Item 2 [57-67] (Internal):
966 Parent: 1
967 Callable 15 [57-67] (function):
968 name: Ident 16 [57-67] "<lambda>"
969 input: Pat 14 [57-67] [Type (Int,)]: Tuple:
970 Pat 9 [57-58] [Type Int]: Bind: Ident 10 [57-58] "x"
971 output: Int
972 functors: empty set
973 body: SpecDecl 17 [62-67]: Impl:
974 Block 18 [62-67] [Type Int]:
975 Stmt 19 [62-67]: Expr: Expr 11 [62-67] [Type Int]: BinOp (Add):
976 Expr 12 [62-63] [Type Int]: Var: Local 10
977 Expr 13 [66-67] [Type Int]: Lit: Int(1)
978 adj: <none>
979 ctl: <none>
980 ctl-adj: <none>"#]],
981 );
982}
983
984#[test]
985fn lambda_function_empty_closure_passed() {
986 check_hir(
987 indoc! {"
988 namespace A {
989 function Foo(f : Int -> Int) : Int { f(2) }
990 function Bar() : Int { Foo(x -> x + 1) }
991 }
992 "},
993 &expect![[r#"
994 Package:
995 Item 0 [0-108] (Public):
996 Namespace (Ident 30 [10-11] "A"): Item 1, Item 2
997 Item 1 [18-61] (Internal):
998 Parent: 0
999 Callable 0 [18-61] (function):
1000 name: Ident 1 [27-30] "Foo"
1001 input: Pat 2 [31-45] [Type (Int -> Int)]: Bind: Ident 3 [31-32] "f"
1002 output: Int
1003 functors: empty set
1004 body: SpecDecl 4 [18-61]: Impl:
1005 Block 5 [53-61] [Type Int]:
1006 Stmt 6 [55-59]: Expr: Expr 7 [55-59] [Type Int]: Call:
1007 Expr 8 [55-56] [Type (Int -> Int)]: Var: Local 3
1008 Expr 9 [57-58] [Type Int]: Lit: Int(2)
1009 adj: <none>
1010 ctl: <none>
1011 ctl-adj: <none>
1012 Item 2 [66-106] (Internal):
1013 Parent: 0
1014 Callable 10 [66-106] (function):
1015 name: Ident 11 [75-78] "Bar"
1016 input: Pat 12 [78-80] [Type Unit]: Unit
1017 output: Int
1018 functors: empty set
1019 body: SpecDecl 13 [66-106]: Impl:
1020 Block 14 [87-106] [Type Int]:
1021 Stmt 15 [89-104]: Expr: Expr 16 [89-104] [Type Int]: Call:
1022 Expr 17 [89-92] [Type ((Int -> Int) -> Int)]: Var: Item 1 (Package 1)
1023 Expr 18 [93-103] [Type (Int -> Int)]: Closure([], 3)
1024 adj: <none>
1025 ctl: <none>
1026 ctl-adj: <none>
1027 Item 3 [93-103] (Internal):
1028 Parent: 2
1029 Callable 25 [93-103] (function):
1030 name: Ident 26 [93-103] "<lambda>"
1031 input: Pat 24 [93-103] [Type (Int,)]: Tuple:
1032 Pat 19 [93-94] [Type Int]: Bind: Ident 20 [93-94] "x"
1033 output: Int
1034 functors: empty set
1035 body: SpecDecl 27 [98-103]: Impl:
1036 Block 28 [98-103] [Type Int]:
1037 Stmt 29 [98-103]: Expr: Expr 21 [98-103] [Type Int]: BinOp (Add):
1038 Expr 22 [98-99] [Type Int]: Var: Local 20
1039 Expr 23 [102-103] [Type Int]: Lit: Int(1)
1040 adj: <none>
1041 ctl: <none>
1042 ctl-adj: <none>"#]],
1043 );
1044}
1045
1046#[test]
1047fn lambda_function_closure() {
1048 check_hir(
1049 indoc! {"
1050 namespace A {
1051 function Foo() : Int {
1052 let x = 5;
1053 let f = y -> x + y;
1054 f(2)
1055 }
1056 }
1057 "},
1058 &expect![[r#"
1059 Package:
1060 Item 0 [0-108] (Public):
1061 Namespace (Ident 30 [10-11] "A"): Item 1
1062 Item 1 [18-106] (Internal):
1063 Parent: 0
1064 Callable 0 [18-106] (function):
1065 name: Ident 1 [27-30] "Foo"
1066 input: Pat 2 [30-32] [Type Unit]: Unit
1067 output: Int
1068 functors: empty set
1069 body: SpecDecl 3 [18-106]: Impl:
1070 Block 4 [39-106] [Type Int]:
1071 Stmt 5 [49-59]: Local (Immutable):
1072 Pat 6 [53-54] [Type Int]: Bind: Ident 7 [53-54] "x"
1073 Expr 8 [57-58] [Type Int]: Lit: Int(5)
1074 Stmt 9 [68-87]: Local (Immutable):
1075 Pat 10 [72-73] [Type (Int -> Int)]: Bind: Ident 11 [72-73] "f"
1076 Expr 12 [76-86] [Type (Int -> Int)]: Closure([7], 2)
1077 Stmt 26 [96-100]: Expr: Expr 27 [96-100] [Type Int]: Call:
1078 Expr 28 [96-97] [Type (Int -> Int)]: Var: Local 11
1079 Expr 29 [98-99] [Type Int]: Lit: Int(2)
1080 adj: <none>
1081 ctl: <none>
1082 ctl-adj: <none>
1083 Item 2 [76-86] (Internal):
1084 Parent: 1
1085 Callable 21 [76-86] (function):
1086 name: Ident 22 [76-86] "<lambda>"
1087 input: Pat 19 [76-86] [Type (Int, Int)]: Tuple:
1088 Pat 20 [53-54] [Type Int]: Bind: Ident 18 [53-54] "x"
1089 Pat 13 [76-77] [Type Int]: Bind: Ident 14 [76-77] "y"
1090 output: Int
1091 functors: empty set
1092 body: SpecDecl 23 [81-86]: Impl:
1093 Block 24 [81-86] [Type Int]:
1094 Stmt 25 [81-86]: Expr: Expr 15 [81-86] [Type Int]: BinOp (Add):
1095 Expr 16 [81-82] [Type Int]: Var: Local 18
1096 Expr 17 [85-86] [Type Int]: Var: Local 14
1097 adj: <none>
1098 ctl: <none>
1099 ctl-adj: <none>"#]],
1100 );
1101}
1102
1103#[test]
1104fn lambda_function_closure_repeated_var() {
1105 check_hir(
1106 indoc! {"
1107 namespace A {
1108 function Foo() : Int {
1109 let x = 5;
1110 let f = y -> x + x + y;
1111 f(2)
1112 }
1113 }
1114 "},
1115 &expect![[r#"
1116 Package:
1117 Item 0 [0-112] (Public):
1118 Namespace (Ident 32 [10-11] "A"): Item 1
1119 Item 1 [18-110] (Internal):
1120 Parent: 0
1121 Callable 0 [18-110] (function):
1122 name: Ident 1 [27-30] "Foo"
1123 input: Pat 2 [30-32] [Type Unit]: Unit
1124 output: Int
1125 functors: empty set
1126 body: SpecDecl 3 [18-110]: Impl:
1127 Block 4 [39-110] [Type Int]:
1128 Stmt 5 [49-59]: Local (Immutable):
1129 Pat 6 [53-54] [Type Int]: Bind: Ident 7 [53-54] "x"
1130 Expr 8 [57-58] [Type Int]: Lit: Int(5)
1131 Stmt 9 [68-91]: Local (Immutable):
1132 Pat 10 [72-73] [Type (Int -> Int)]: Bind: Ident 11 [72-73] "f"
1133 Expr 12 [76-90] [Type (Int -> Int)]: Closure([7], 2)
1134 Stmt 28 [100-104]: Expr: Expr 29 [100-104] [Type Int]: Call:
1135 Expr 30 [100-101] [Type (Int -> Int)]: Var: Local 11
1136 Expr 31 [102-103] [Type Int]: Lit: Int(2)
1137 adj: <none>
1138 ctl: <none>
1139 ctl-adj: <none>
1140 Item 2 [76-90] (Internal):
1141 Parent: 1
1142 Callable 23 [76-90] (function):
1143 name: Ident 24 [76-90] "<lambda>"
1144 input: Pat 21 [76-90] [Type (Int, Int)]: Tuple:
1145 Pat 22 [53-54] [Type Int]: Bind: Ident 20 [53-54] "x"
1146 Pat 13 [76-77] [Type Int]: Bind: Ident 14 [76-77] "y"
1147 output: Int
1148 functors: empty set
1149 body: SpecDecl 25 [81-90]: Impl:
1150 Block 26 [81-90] [Type Int]:
1151 Stmt 27 [81-90]: Expr: Expr 15 [81-90] [Type Int]: BinOp (Add):
1152 Expr 16 [81-86] [Type Int]: BinOp (Add):
1153 Expr 17 [81-82] [Type Int]: Var: Local 20
1154 Expr 18 [85-86] [Type Int]: Var: Local 20
1155 Expr 19 [89-90] [Type Int]: Var: Local 14
1156 adj: <none>
1157 ctl: <none>
1158 ctl-adj: <none>"#]],
1159 );
1160}
1161
1162#[test]
1163fn lambda_function_closure_passed() {
1164 check_hir(
1165 indoc! {"
1166 namespace A {
1167 function Foo(f : Int -> Int) : Int { f(2) }
1168 function Bar() : Int {
1169 let x = 5;
1170 Foo(y -> x + y)
1171 }
1172 }
1173 "},
1174 &expect![[r#"
1175 Package:
1176 Item 0 [0-139] (Public):
1177 Namespace (Ident 36 [10-11] "A"): Item 1, Item 2
1178 Item 1 [18-61] (Internal):
1179 Parent: 0
1180 Callable 0 [18-61] (function):
1181 name: Ident 1 [27-30] "Foo"
1182 input: Pat 2 [31-45] [Type (Int -> Int)]: Bind: Ident 3 [31-32] "f"
1183 output: Int
1184 functors: empty set
1185 body: SpecDecl 4 [18-61]: Impl:
1186 Block 5 [53-61] [Type Int]:
1187 Stmt 6 [55-59]: Expr: Expr 7 [55-59] [Type Int]: Call:
1188 Expr 8 [55-56] [Type (Int -> Int)]: Var: Local 3
1189 Expr 9 [57-58] [Type Int]: Lit: Int(2)
1190 adj: <none>
1191 ctl: <none>
1192 ctl-adj: <none>
1193 Item 2 [66-137] (Internal):
1194 Parent: 0
1195 Callable 10 [66-137] (function):
1196 name: Ident 11 [75-78] "Bar"
1197 input: Pat 12 [78-80] [Type Unit]: Unit
1198 output: Int
1199 functors: empty set
1200 body: SpecDecl 13 [66-137]: Impl:
1201 Block 14 [87-137] [Type Int]:
1202 Stmt 15 [97-107]: Local (Immutable):
1203 Pat 16 [101-102] [Type Int]: Bind: Ident 17 [101-102] "x"
1204 Expr 18 [105-106] [Type Int]: Lit: Int(5)
1205 Stmt 19 [116-131]: Expr: Expr 20 [116-131] [Type Int]: Call:
1206 Expr 21 [116-119] [Type ((Int -> Int) -> Int)]: Var: Item 1 (Package 1)
1207 Expr 22 [120-130] [Type (Int -> Int)]: Closure([17], 3)
1208 adj: <none>
1209 ctl: <none>
1210 ctl-adj: <none>
1211 Item 3 [120-130] (Internal):
1212 Parent: 2
1213 Callable 31 [120-130] (function):
1214 name: Ident 32 [120-130] "<lambda>"
1215 input: Pat 29 [120-130] [Type (Int, Int)]: Tuple:
1216 Pat 30 [101-102] [Type Int]: Bind: Ident 28 [101-102] "x"
1217 Pat 23 [120-121] [Type Int]: Bind: Ident 24 [120-121] "y"
1218 output: Int
1219 functors: empty set
1220 body: SpecDecl 33 [125-130]: Impl:
1221 Block 34 [125-130] [Type Int]:
1222 Stmt 35 [125-130]: Expr: Expr 25 [125-130] [Type Int]: BinOp (Add):
1223 Expr 26 [125-126] [Type Int]: Var: Local 28
1224 Expr 27 [129-130] [Type Int]: Var: Local 24
1225 adj: <none>
1226 ctl: <none>
1227 ctl-adj: <none>"#]],
1228 );
1229}
1230
1231#[test]
1232fn lambda_function_nested_closure() {
1233 check_hir(
1234 indoc! {"
1235 namespace A {
1236 function Foo(f : Int -> Int -> Int) : Int { f(2)(3) }
1237 function Bar() : Int {
1238 let a = 5;
1239 Foo(b -> {
1240 let c = 1;
1241 d -> a + b + c + d
1242 })
1243 }
1244 }
1245 "},
1246 &expect![[r#"
1247 Package:
1248 Item 0 [0-209] (Public):
1249 Namespace (Ident 64 [10-11] "A"): Item 1, Item 2
1250 Item 1 [18-71] (Internal):
1251 Parent: 0
1252 Callable 0 [18-71] (function):
1253 name: Ident 1 [27-30] "Foo"
1254 input: Pat 2 [31-52] [Type (Int -> (Int -> Int))]: Bind: Ident 3 [31-32] "f"
1255 output: Int
1256 functors: empty set
1257 body: SpecDecl 4 [18-71]: Impl:
1258 Block 5 [60-71] [Type Int]:
1259 Stmt 6 [62-69]: Expr: Expr 7 [62-69] [Type Int]: Call:
1260 Expr 8 [62-66] [Type (Int -> Int)]: Call:
1261 Expr 9 [62-63] [Type (Int -> (Int -> Int))]: Var: Local 3
1262 Expr 10 [64-65] [Type Int]: Lit: Int(2)
1263 Expr 11 [67-68] [Type Int]: Lit: Int(3)
1264 adj: <none>
1265 ctl: <none>
1266 ctl-adj: <none>
1267 Item 2 [76-207] (Internal):
1268 Parent: 0
1269 Callable 12 [76-207] (function):
1270 name: Ident 13 [85-88] "Bar"
1271 input: Pat 14 [88-90] [Type Unit]: Unit
1272 output: Int
1273 functors: empty set
1274 body: SpecDecl 15 [76-207]: Impl:
1275 Block 16 [97-207] [Type Int]:
1276 Stmt 17 [107-117]: Local (Immutable):
1277 Pat 18 [111-112] [Type Int]: Bind: Ident 19 [111-112] "a"
1278 Expr 20 [115-116] [Type Int]: Lit: Int(5)
1279 Stmt 21 [126-201]: Expr: Expr 22 [126-201] [Type Int]: Call:
1280 Expr 23 [126-129] [Type ((Int -> (Int -> Int)) -> Int)]: Var: Item 1 (Package 1)
1281 Expr 24 [130-200] [Type (Int -> (Int -> Int))]: Closure([19], 4)
1282 adj: <none>
1283 ctl: <none>
1284 ctl-adj: <none>
1285 Item 3 [172-190] (Internal):
1286 Parent: 2
1287 Callable 51 [172-190] (function):
1288 name: Ident 52 [172-190] "<lambda>"
1289 input: Pat 47 [172-190] [Type (Int, Int, Int, Int)]: Tuple:
1290 Pat 48 [111-112] [Type Int]: Bind: Ident 44 [111-112] "a"
1291 Pat 49 [130-131] [Type Int]: Bind: Ident 45 [130-131] "b"
1292 Pat 50 [153-154] [Type Int]: Bind: Ident 46 [153-154] "c"
1293 Pat 35 [172-173] [Type Int]: Bind: Ident 36 [172-173] "d"
1294 output: Int
1295 functors: empty set
1296 body: SpecDecl 53 [177-190]: Impl:
1297 Block 54 [177-190] [Type Int]:
1298 Stmt 55 [177-190]: Expr: Expr 37 [177-190] [Type Int]: BinOp (Add):
1299 Expr 38 [177-186] [Type Int]: BinOp (Add):
1300 Expr 39 [177-182] [Type Int]: BinOp (Add):
1301 Expr 40 [177-178] [Type Int]: Var: Local 44
1302 Expr 41 [181-182] [Type Int]: Var: Local 45
1303 Expr 42 [185-186] [Type Int]: Var: Local 46
1304 Expr 43 [189-190] [Type Int]: Var: Local 36
1305 adj: <none>
1306 ctl: <none>
1307 ctl-adj: <none>
1308 Item 4 [130-200] (Internal):
1309 Parent: 2
1310 Callable 59 [130-200] (function):
1311 name: Ident 60 [130-200] "<lambda>"
1312 input: Pat 57 [130-200] [Type (Int, Int)]: Tuple:
1313 Pat 58 [111-112] [Type Int]: Bind: Ident 56 [111-112] "a"
1314 Pat 25 [130-131] [Type Int]: Bind: Ident 26 [130-131] "b"
1315 output: (Int -> Int)
1316 functors: empty set
1317 body: SpecDecl 61 [135-200]: Impl:
1318 Block 62 [135-200] [Type (Int -> Int)]:
1319 Stmt 63 [135-200]: Expr: Expr 27 [135-200] [Type (Int -> Int)]: Expr Block: Block 28 [135-200] [Type (Int -> Int)]:
1320 Stmt 29 [149-159]: Local (Immutable):
1321 Pat 30 [153-154] [Type Int]: Bind: Ident 31 [153-154] "c"
1322 Expr 32 [157-158] [Type Int]: Lit: Int(1)
1323 Stmt 33 [172-190]: Expr: Expr 34 [172-190] [Type (Int -> Int)]: Closure([56, 26, 31], 3)
1324 adj: <none>
1325 ctl: <none>
1326 ctl-adj: <none>"#]],
1327 );
1328}
1329
1330#[test]
1331fn lambda_operation_empty_closure() {
1332 check_hir(
1333 indoc! {"
1334 namespace A {
1335 operation Foo(op : Qubit => ()) : () {
1336 use q = Qubit();
1337 op(q)
1338 }
1339 operation Bar() : Result { Foo(q => ()) }
1340 }
1341 "},
1342 &expect![[r#"
1343 Package:
1344 Item 0 [0-149] (Public):
1345 Namespace (Ident 32 [10-11] "A"): Item 1, Item 2
1346 Item 1 [18-101] (Internal):
1347 Parent: 0
1348 Callable 0 [18-101] (operation):
1349 name: Ident 1 [28-31] "Foo"
1350 generics:
1351 0: functor (empty set)
1352 input: Pat 2 [32-48] [Type (Qubit => Unit is Param<0>)]: Bind: Ident 3 [32-34] "op"
1353 output: Unit
1354 functors: empty set
1355 body: SpecDecl 4 [18-101]: Impl:
1356 Block 5 [55-101] [Type Unit]:
1357 Stmt 6 [65-81]: Qubit (Fresh)
1358 Pat 7 [69-70] [Type Qubit]: Bind: Ident 8 [69-70] "q"
1359 QubitInit 9 [73-80] [Type Qubit]: Single
1360 Stmt 10 [90-95]: Expr: Expr 11 [90-95] [Type Unit]: Call:
1361 Expr 12 [90-92] [Type (Qubit => Unit is Param<0>)]: Var: Local 3
1362 Expr 13 [93-94] [Type Qubit]: Var: Local 8
1363 adj: <none>
1364 ctl: <none>
1365 ctl-adj: <none>
1366 Item 2 [106-147] (Internal):
1367 Parent: 0
1368 Callable 14 [106-147] (operation):
1369 name: Ident 15 [116-119] "Bar"
1370 input: Pat 16 [119-121] [Type Unit]: Unit
1371 output: Result
1372 functors: empty set
1373 body: SpecDecl 17 [106-147]: Impl:
1374 Block 18 [131-147] [Type Unit]:
1375 Stmt 19 [133-145]: Expr: Expr 20 [133-145] [Type Unit]: Call:
1376 Expr 21 [133-136] [Type ((Qubit => Unit) => Unit)]: Var:
1377 res: Item 1 (Package 1)
1378 generics:
1379 empty set
1380 Expr 22 [137-144] [Type (Qubit => Unit)]: Closure([], 3)
1381 adj: <none>
1382 ctl: <none>
1383 ctl-adj: <none>
1384 Item 3 [137-144] (Internal):
1385 Parent: 2
1386 Callable 27 [137-144] (operation):
1387 name: Ident 28 [137-144] "<lambda>"
1388 input: Pat 26 [137-144] [Type (Qubit,)]: Tuple:
1389 Pat 23 [137-138] [Type Qubit]: Bind: Ident 24 [137-138] "q"
1390 output: Unit
1391 functors: empty set
1392 body: SpecDecl 29 [142-144]: Impl:
1393 Block 30 [142-144] [Type Unit]:
1394 Stmt 31 [142-144]: Expr: Expr 25 [142-144] [Type Unit]: Unit
1395 adj: <none>
1396 ctl: <none>
1397 ctl-adj: <none>"#]],
1398 );
1399}
1400
1401#[test]
1402fn lambda_operation_closure() {
1403 check_hir(
1404 indoc! {"
1405 namespace A {
1406 operation MResetZ(q : Qubit) : Result { body intrinsic; }
1407 operation Foo(op : () => Result) : Result { op() }
1408 operation Bar() : Result {
1409 use q = Qubit();
1410 Foo(() => MResetZ(q))
1411 }
1412 }
1413 "},
1414 &expect![[r#"
1415 Package:
1416 Item 0 [0-224] (Public):
1417 Namespace (Ident 40 [10-11] "A"): Item 1, Item 2, Item 3
1418 Item 1 [18-75] (Internal):
1419 Parent: 0
1420 Callable 0 [18-75] (operation):
1421 name: Ident 1 [28-35] "MResetZ"
1422 input: Pat 2 [36-45] [Type Qubit]: Bind: Ident 3 [36-37] "q"
1423 output: Result
1424 functors: empty set
1425 body: SpecDecl 4 [58-73]: Gen: Intrinsic
1426 adj: <none>
1427 ctl: <none>
1428 ctl-adj: <none>
1429 Item 2 [80-130] (Internal):
1430 Parent: 0
1431 Callable 5 [80-130] (operation):
1432 name: Ident 6 [90-93] "Foo"
1433 generics:
1434 0: functor (empty set)
1435 input: Pat 7 [94-111] [Type (Unit => Result is Param<0>)]: Bind: Ident 8 [94-96] "op"
1436 output: Result
1437 functors: empty set
1438 body: SpecDecl 9 [80-130]: Impl:
1439 Block 10 [122-130] [Type Result]:
1440 Stmt 11 [124-128]: Expr: Expr 12 [124-128] [Type Result]: Call:
1441 Expr 13 [124-126] [Type (Unit => Result is Param<0>)]: Var: Local 8
1442 Expr 14 [126-128] [Type Unit]: Unit
1443 adj: <none>
1444 ctl: <none>
1445 ctl-adj: <none>
1446 Item 3 [135-222] (Internal):
1447 Parent: 0
1448 Callable 15 [135-222] (operation):
1449 name: Ident 16 [145-148] "Bar"
1450 input: Pat 17 [148-150] [Type Unit]: Unit
1451 output: Result
1452 functors: empty set
1453 body: SpecDecl 18 [135-222]: Impl:
1454 Block 19 [160-222] [Type Result]:
1455 Stmt 20 [170-186]: Qubit (Fresh)
1456 Pat 21 [174-175] [Type Qubit]: Bind: Ident 22 [174-175] "q"
1457 QubitInit 23 [178-185] [Type Qubit]: Single
1458 Stmt 24 [195-216]: Expr: Expr 25 [195-216] [Type Result]: Call:
1459 Expr 26 [195-198] [Type ((Unit => Result) => Result)]: Var:
1460 res: Item 2 (Package 1)
1461 generics:
1462 empty set
1463 Expr 27 [199-215] [Type (Unit => Result)]: Closure([22], 4)
1464 adj: <none>
1465 ctl: <none>
1466 ctl-adj: <none>
1467 Item 4 [199-215] (Internal):
1468 Parent: 3
1469 Callable 35 [199-215] (operation):
1470 name: Ident 36 [199-215] "<lambda>"
1471 input: Pat 33 [199-215] [Type (Qubit, Unit)]: Tuple:
1472 Pat 34 [174-175] [Type Qubit]: Bind: Ident 32 [174-175] "q"
1473 Pat 28 [199-201] [Type Unit]: Unit
1474 output: Result
1475 functors: empty set
1476 body: SpecDecl 37 [205-215]: Impl:
1477 Block 38 [205-215] [Type Result]:
1478 Stmt 39 [205-215]: Expr: Expr 29 [205-215] [Type Result]: Call:
1479 Expr 30 [205-212] [Type (Qubit => Result)]: Var: Item 1 (Package 1)
1480 Expr 31 [213-214] [Type Qubit]: Var: Local 32
1481 adj: <none>
1482 ctl: <none>
1483 ctl-adj: <none>"#]],
1484 );
1485}
1486
1487#[test]
1488fn lambda_adj() {
1489 check_hir(
1490 indoc! {r#"
1491 namespace A {
1492 operation X(q : Qubit) : () is Adj {}
1493 operation Foo(op : Qubit => () is Adj) : () {}
1494 operation Bar() : () { Foo(q => X(q)); }
1495 }
1496 "#},
1497 &expect![[r#"
1498 Package:
1499 Item 0 [0-153] (Public):
1500 Namespace (Ident 32 [10-11] "A"): Item 1, Item 2, Item 3
1501 Item 1 [18-55] (Internal):
1502 Parent: 0
1503 Callable 0 [18-55] (operation):
1504 name: Ident 1 [28-29] "X"
1505 input: Pat 2 [30-39] [Type Qubit]: Bind: Ident 3 [30-31] "q"
1506 output: Unit
1507 functors: Adj
1508 body: SpecDecl 4 [18-55]: Impl:
1509 Block 5 [53-55]: <empty>
1510 adj: <none>
1511 ctl: <none>
1512 ctl-adj: <none>
1513 Item 2 [60-106] (Internal):
1514 Parent: 0
1515 Callable 6 [60-106] (operation):
1516 name: Ident 7 [70-73] "Foo"
1517 generics:
1518 0: functor (Adj)
1519 input: Pat 8 [74-97] [Type (Qubit => Unit is Param<0>)]: Bind: Ident 9 [74-76] "op"
1520 output: Unit
1521 functors: empty set
1522 body: SpecDecl 10 [60-106]: Impl:
1523 Block 11 [104-106]: <empty>
1524 adj: <none>
1525 ctl: <none>
1526 ctl-adj: <none>
1527 Item 3 [111-151] (Internal):
1528 Parent: 0
1529 Callable 12 [111-151] (operation):
1530 name: Ident 13 [121-124] "Bar"
1531 input: Pat 14 [124-126] [Type Unit]: Unit
1532 output: Unit
1533 functors: empty set
1534 body: SpecDecl 15 [111-151]: Impl:
1535 Block 16 [132-151] [Type Unit]:
1536 Stmt 17 [134-149]: Semi: Expr 18 [134-148] [Type Unit]: Call:
1537 Expr 19 [134-137] [Type ((Qubit => Unit is Adj) => Unit)]: Var:
1538 res: Item 2 (Package 1)
1539 generics:
1540 Adj
1541 Expr 20 [138-147] [Type (Qubit => Unit is Adj)]: Closure([], 4)
1542 adj: <none>
1543 ctl: <none>
1544 ctl-adj: <none>
1545 Item 4 [138-147] (Internal):
1546 Parent: 3
1547 Callable 27 [138-147] (operation):
1548 name: Ident 28 [138-147] "<lambda>"
1549 input: Pat 26 [138-147] [Type (Qubit,)]: Tuple:
1550 Pat 21 [138-139] [Type Qubit]: Bind: Ident 22 [138-139] "q"
1551 output: Unit
1552 functors: Adj
1553 body: SpecDecl 29 [143-147]: Impl:
1554 Block 30 [143-147] [Type Unit]:
1555 Stmt 31 [143-147]: Expr: Expr 23 [143-147] [Type Unit]: Call:
1556 Expr 24 [143-144] [Type (Qubit => Unit is Adj)]: Var: Item 1 (Package 1)
1557 Expr 25 [145-146] [Type Qubit]: Var: Local 22
1558 adj: <none>
1559 ctl: <none>
1560 ctl-adj: <none>"#]],
1561 );
1562}
1563
1564#[test]
1565fn partial_app_one_hole() {
1566 check_hir(
1567 indoc! {"
1568 namespace A {
1569 function Foo(x : Int, y : Int) : Int { x + y }
1570 function Bar() : () { let f = Foo(_, 2); }
1571 }
1572 "},
1573 &expect![[r#"
1574 Package:
1575 Item 0 [0-113] (Public):
1576 Namespace (Ident 45 [10-11] "A"): Item 1, Item 2
1577 Item 1 [18-64] (Internal):
1578 Parent: 0
1579 Callable 0 [18-64] (function):
1580 name: Ident 1 [27-30] "Foo"
1581 input: Pat 2 [30-48] [Type (Int, Int)]: Tuple:
1582 Pat 3 [31-38] [Type Int]: Bind: Ident 4 [31-32] "x"
1583 Pat 5 [40-47] [Type Int]: Bind: Ident 6 [40-41] "y"
1584 output: Int
1585 functors: empty set
1586 body: SpecDecl 7 [18-64]: Impl:
1587 Block 8 [55-64] [Type Int]:
1588 Stmt 9 [57-62]: Expr: Expr 10 [57-62] [Type Int]: BinOp (Add):
1589 Expr 11 [57-58] [Type Int]: Var: Local 4
1590 Expr 12 [61-62] [Type Int]: Var: Local 6
1591 adj: <none>
1592 ctl: <none>
1593 ctl-adj: <none>
1594 Item 2 [69-111] (Internal):
1595 Parent: 0
1596 Callable 13 [69-111] (function):
1597 name: Ident 14 [78-81] "Bar"
1598 input: Pat 15 [81-83] [Type Unit]: Unit
1599 output: Unit
1600 functors: empty set
1601 body: SpecDecl 16 [69-111]: Impl:
1602 Block 17 [89-111] [Type Unit]:
1603 Stmt 18 [91-109]: Local (Immutable):
1604 Pat 19 [95-96] [Type (Int -> Int)]: Bind: Ident 20 [95-96] "f"
1605 Expr 21 [99-108] [Type (Int -> Int)]: Expr Block: Block 42 [99-108] [Type (Int -> Int)]:
1606 Stmt 30 [106-107]: Local (Immutable):
1607 Pat 29 [106-107] [Type Int]: Bind: Ident 27 [106-107] "arg"
1608 Expr 26 [106-107] [Type Int]: Lit: Int(2)
1609 Stmt 43 [99-108]: Expr: Expr 44 [99-108] [Type (Int -> Int)]: Closure([27], 3)
1610 adj: <none>
1611 ctl: <none>
1612 ctl-adj: <none>
1613 Item 3 [99-108] (Internal):
1614 Parent: 2
1615 Callable 37 [99-108] (function):
1616 name: Ident 38 [99-108] "<lambda>"
1617 input: Pat 35 [99-108] [Type (Int, Int)]: Tuple:
1618 Pat 36 [106-107] [Type Int]: Bind: Ident 34 [106-107] "arg"
1619 Pat 24 [103-104] [Type Int]: Bind: Ident 23 [103-104] "hole"
1620 output: Int
1621 functors: empty set
1622 body: SpecDecl 39 [99-108]: Impl:
1623 Block 40 [99-108] [Type Int]:
1624 Stmt 41 [99-108]: Expr: Expr 33 [99-108] [Type Int]: Call:
1625 Expr 22 [99-102] [Type ((Int, Int) -> Int)]: Var: Item 1 (Package 1)
1626 Expr 32 [102-108] [Type (Int, Int)]: Tuple:
1627 Expr 25 [103-104] [Type Int]: Var: Local 23
1628 Expr 28 [106-107] [Type Int]: Var: Local 34
1629 adj: <none>
1630 ctl: <none>
1631 ctl-adj: <none>"#]],
1632 );
1633}
1634
1635#[test]
1636fn partial_app_two_holes() {
1637 check_hir(
1638 indoc! {"
1639 namespace A {
1640 function Foo(x : Int, y : Int) : Int { x + y }
1641 function Bar() : () { let f = Foo(_, _); }
1642 }
1643 "},
1644 &expect![[r#"
1645 Package:
1646 Item 0 [0-113] (Public):
1647 Namespace (Ident 41 [10-11] "A"): Item 1, Item 2
1648 Item 1 [18-64] (Internal):
1649 Parent: 0
1650 Callable 0 [18-64] (function):
1651 name: Ident 1 [27-30] "Foo"
1652 input: Pat 2 [30-48] [Type (Int, Int)]: Tuple:
1653 Pat 3 [31-38] [Type Int]: Bind: Ident 4 [31-32] "x"
1654 Pat 5 [40-47] [Type Int]: Bind: Ident 6 [40-41] "y"
1655 output: Int
1656 functors: empty set
1657 body: SpecDecl 7 [18-64]: Impl:
1658 Block 8 [55-64] [Type Int]:
1659 Stmt 9 [57-62]: Expr: Expr 10 [57-62] [Type Int]: BinOp (Add):
1660 Expr 11 [57-58] [Type Int]: Var: Local 4
1661 Expr 12 [61-62] [Type Int]: Var: Local 6
1662 adj: <none>
1663 ctl: <none>
1664 ctl-adj: <none>
1665 Item 2 [69-111] (Internal):
1666 Parent: 0
1667 Callable 13 [69-111] (function):
1668 name: Ident 14 [78-81] "Bar"
1669 input: Pat 15 [81-83] [Type Unit]: Unit
1670 output: Unit
1671 functors: empty set
1672 body: SpecDecl 16 [69-111]: Impl:
1673 Block 17 [89-111] [Type Unit]:
1674 Stmt 18 [91-109]: Local (Immutable):
1675 Pat 19 [95-96] [Type ((Int, Int) -> Int)]: Bind: Ident 20 [95-96] "f"
1676 Expr 21 [99-108] [Type ((Int, Int) -> Int)]: Expr Block: Block 38 [99-108] [Type ((Int, Int) -> Int)]:
1677 Stmt 39 [99-108]: Expr: Expr 40 [99-108] [Type ((Int, Int) -> Int)]: Closure([], 3)
1678 adj: <none>
1679 ctl: <none>
1680 ctl-adj: <none>
1681 Item 3 [99-108] (Internal):
1682 Parent: 2
1683 Callable 33 [99-108] (function):
1684 name: Ident 34 [99-108] "<lambda>"
1685 input: Pat 32 [99-108] [Type ((Int, Int),)]: Tuple:
1686 Pat 30 [102-108] [Type (Int, Int)]: Tuple:
1687 Pat 24 [103-104] [Type Int]: Bind: Ident 23 [103-104] "hole"
1688 Pat 27 [106-107] [Type Int]: Bind: Ident 26 [106-107] "hole"
1689 output: Int
1690 functors: empty set
1691 body: SpecDecl 35 [99-108]: Impl:
1692 Block 36 [99-108] [Type Int]:
1693 Stmt 37 [99-108]: Expr: Expr 31 [99-108] [Type Int]: Call:
1694 Expr 22 [99-102] [Type ((Int, Int) -> Int)]: Var: Item 1 (Package 1)
1695 Expr 29 [102-108] [Type (Int, Int)]: Tuple:
1696 Expr 25 [103-104] [Type Int]: Var: Local 23
1697 Expr 28 [106-107] [Type Int]: Var: Local 26
1698 adj: <none>
1699 ctl: <none>
1700 ctl-adj: <none>"#]],
1701 );
1702}
1703
1704#[test]
1705fn partial_app_nested_tuple() {
1706 check_hir(
1707 indoc! {"
1708 namespace A {
1709 function Foo(a : Int, (b : Bool, c : Double, d : String), e : Result) : () {}
1710 function Bar() : () { let f = Foo(_, (_, 1.0, _), _); }
1711 }
1712 "},
1713 &expect![[r#"
1714 Package:
1715 Item 0 [0-157] (Public):
1716 Namespace (Ident 60 [10-11] "A"): Item 1, Item 2
1717 Item 1 [18-95] (Internal):
1718 Parent: 0
1719 Callable 0 [18-95] (function):
1720 name: Ident 1 [27-30] "Foo"
1721 input: Pat 2 [30-87] [Type (Int, (Bool, Double, String), Result)]: Tuple:
1722 Pat 3 [31-38] [Type Int]: Bind: Ident 4 [31-32] "a"
1723 Pat 5 [40-74] [Type (Bool, Double, String)]: Tuple:
1724 Pat 6 [41-49] [Type Bool]: Bind: Ident 7 [41-42] "b"
1725 Pat 8 [51-61] [Type Double]: Bind: Ident 9 [51-52] "c"
1726 Pat 10 [63-73] [Type String]: Bind: Ident 11 [63-64] "d"
1727 Pat 12 [76-86] [Type Result]: Bind: Ident 13 [76-77] "e"
1728 output: Unit
1729 functors: empty set
1730 body: SpecDecl 14 [18-95]: Impl:
1731 Block 15 [93-95]: <empty>
1732 adj: <none>
1733 ctl: <none>
1734 ctl-adj: <none>
1735 Item 2 [100-155] (Internal):
1736 Parent: 0
1737 Callable 16 [100-155] (function):
1738 name: Ident 17 [109-112] "Bar"
1739 input: Pat 18 [112-114] [Type Unit]: Unit
1740 output: Unit
1741 functors: empty set
1742 body: SpecDecl 19 [100-155]: Impl:
1743 Block 20 [120-155] [Type Unit]:
1744 Stmt 21 [122-153]: Local (Immutable):
1745 Pat 22 [126-127] [Type ((Int, (Bool, String), Result) -> Unit)]: Bind: Ident 23 [126-127] "f"
1746 Expr 24 [130-152] [Type ((Int, (Bool, String), Result) -> Unit)]: Expr Block: Block 57 [130-152] [Type ((Int, (Bool, String), Result) -> Unit)]:
1747 Stmt 36 [141-144]: Local (Immutable):
1748 Pat 35 [141-144] [Type Double]: Bind: Ident 33 [141-144] "arg"
1749 Expr 32 [141-144] [Type Double]: Lit: Double(1)
1750 Stmt 58 [130-152]: Expr: Expr 59 [130-152] [Type ((Int, (Bool, String), Result) -> Unit)]: Closure([33], 3)
1751 adj: <none>
1752 ctl: <none>
1753 ctl-adj: <none>
1754 Item 3 [130-152] (Internal):
1755 Parent: 2
1756 Callable 52 [130-152] (function):
1757 name: Ident 53 [130-152] "<lambda>"
1758 input: Pat 50 [130-152] [Type (Double, (Int, (Bool, String), Result))]: Tuple:
1759 Pat 51 [141-144] [Type Double]: Bind: Ident 49 [141-144] "arg"
1760 Pat 47 [133-152] [Type (Int, (Bool, String), Result)]: Tuple:
1761 Pat 27 [134-135] [Type Int]: Bind: Ident 26 [134-135] "hole"
1762 Pat 42 [137-148] [Type (Bool, String)]: Tuple:
1763 Pat 30 [138-139] [Type Bool]: Bind: Ident 29 [138-139] "hole"
1764 Pat 39 [146-147] [Type String]: Bind: Ident 38 [146-147] "hole"
1765 Pat 44 [150-151] [Type Result]: Bind: Ident 43 [150-151] "hole"
1766 output: Unit
1767 functors: empty set
1768 body: SpecDecl 54 [130-152]: Impl:
1769 Block 55 [130-152] [Type Unit]:
1770 Stmt 56 [130-152]: Expr: Expr 48 [130-152] [Type Unit]: Call:
1771 Expr 25 [130-133] [Type ((Int, (Bool, Double, String), Result) -> Unit)]: Var: Item 1 (Package 1)
1772 Expr 46 [133-152] [Type (Int, (Bool, Double, String), Result)]: Tuple:
1773 Expr 28 [134-135] [Type Int]: Var: Local 26
1774 Expr 41 [137-148] [Type (Bool, Double, String)]: Tuple:
1775 Expr 31 [138-139] [Type Bool]: Var: Local 29
1776 Expr 34 [141-144] [Type Double]: Var: Local 49
1777 Expr 40 [146-147] [Type String]: Var: Local 38
1778 Expr 45 [150-151] [Type Result]: Var: Local 43
1779 adj: <none>
1780 ctl: <none>
1781 ctl-adj: <none>"#]],
1782 );
1783}
1784
1785#[test]
1786fn partial_app_nested_tuple_singleton_unwrap() {
1787 check_hir(
1788 indoc! {"
1789 namespace A {
1790 function Foo(a : Int, (b : Bool, c : Double, d : String), e : Result) : () {}
1791 function Bar() : () { let f = Foo(_, (true, 1.0, _), _); }
1792 }
1793 "},
1794 &expect![[r#"
1795 Package:
1796 Item 0 [0-160] (Public):
1797 Namespace (Ident 64 [10-11] "A"): Item 1, Item 2
1798 Item 1 [18-95] (Internal):
1799 Parent: 0
1800 Callable 0 [18-95] (function):
1801 name: Ident 1 [27-30] "Foo"
1802 input: Pat 2 [30-87] [Type (Int, (Bool, Double, String), Result)]: Tuple:
1803 Pat 3 [31-38] [Type Int]: Bind: Ident 4 [31-32] "a"
1804 Pat 5 [40-74] [Type (Bool, Double, String)]: Tuple:
1805 Pat 6 [41-49] [Type Bool]: Bind: Ident 7 [41-42] "b"
1806 Pat 8 [51-61] [Type Double]: Bind: Ident 9 [51-52] "c"
1807 Pat 10 [63-73] [Type String]: Bind: Ident 11 [63-64] "d"
1808 Pat 12 [76-86] [Type Result]: Bind: Ident 13 [76-77] "e"
1809 output: Unit
1810 functors: empty set
1811 body: SpecDecl 14 [18-95]: Impl:
1812 Block 15 [93-95]: <empty>
1813 adj: <none>
1814 ctl: <none>
1815 ctl-adj: <none>
1816 Item 2 [100-158] (Internal):
1817 Parent: 0
1818 Callable 16 [100-158] (function):
1819 name: Ident 17 [109-112] "Bar"
1820 input: Pat 18 [112-114] [Type Unit]: Unit
1821 output: Unit
1822 functors: empty set
1823 body: SpecDecl 19 [100-158]: Impl:
1824 Block 20 [120-158] [Type Unit]:
1825 Stmt 21 [122-156]: Local (Immutable):
1826 Pat 22 [126-127] [Type ((Int, String, Result) -> Unit)]: Bind: Ident 23 [126-127] "f"
1827 Expr 24 [130-155] [Type ((Int, String, Result) -> Unit)]: Expr Block: Block 61 [130-155] [Type ((Int, String, Result) -> Unit)]:
1828 Stmt 33 [138-142]: Local (Immutable):
1829 Pat 32 [138-142] [Type Bool]: Bind: Ident 30 [138-142] "arg"
1830 Expr 29 [138-142] [Type Bool]: Lit: Bool(true)
1831 Stmt 39 [144-147]: Local (Immutable):
1832 Pat 38 [144-147] [Type Double]: Bind: Ident 36 [144-147] "arg"
1833 Expr 35 [144-147] [Type Double]: Lit: Double(1)
1834 Stmt 62 [130-155]: Expr: Expr 63 [130-155] [Type ((Int, String, Result) -> Unit)]: Closure([30, 36], 3)
1835 adj: <none>
1836 ctl: <none>
1837 ctl-adj: <none>
1838 Item 3 [130-155] (Internal):
1839 Parent: 2
1840 Callable 56 [130-155] (function):
1841 name: Ident 57 [130-155] "<lambda>"
1842 input: Pat 53 [130-155] [Type (Bool, Double, (Int, String, Result))]: Tuple:
1843 Pat 54 [138-142] [Type Bool]: Bind: Ident 51 [138-142] "arg"
1844 Pat 55 [144-147] [Type Double]: Bind: Ident 52 [144-147] "arg"
1845 Pat 49 [133-155] [Type (Int, String, Result)]: Tuple:
1846 Pat 27 [134-135] [Type Int]: Bind: Ident 26 [134-135] "hole"
1847 Pat 42 [149-150] [Type String]: Bind: Ident 41 [149-150] "hole"
1848 Pat 46 [153-154] [Type Result]: Bind: Ident 45 [153-154] "hole"
1849 output: Unit
1850 functors: empty set
1851 body: SpecDecl 58 [130-155]: Impl:
1852 Block 59 [130-155] [Type Unit]:
1853 Stmt 60 [130-155]: Expr: Expr 50 [130-155] [Type Unit]: Call:
1854 Expr 25 [130-133] [Type ((Int, (Bool, Double, String), Result) -> Unit)]: Var: Item 1 (Package 1)
1855 Expr 48 [133-155] [Type (Int, (Bool, Double, String), Result)]: Tuple:
1856 Expr 28 [134-135] [Type Int]: Var: Local 26
1857 Expr 44 [137-151] [Type (Bool, Double, String)]: Tuple:
1858 Expr 31 [138-142] [Type Bool]: Var: Local 51
1859 Expr 37 [144-147] [Type Double]: Var: Local 52
1860 Expr 43 [149-150] [Type String]: Var: Local 41
1861 Expr 47 [153-154] [Type Result]: Var: Local 45
1862 adj: <none>
1863 ctl: <none>
1864 ctl-adj: <none>"#]],
1865 );
1866}
1867
1868#[test]
1869fn body_missing_should_fail() {
1870 check_errors(
1871 indoc! {"
1872 namespace test {
1873 operation A(q : Qubit) : Unit is Adj {
1874 adjoint ... {}
1875 }
1876 }
1877 "},
1878 &expect![[r#"
1879 [
1880 MissingBody(
1881 Span {
1882 lo: 21,
1883 hi: 88,
1884 },
1885 ),
1886 ]
1887 "#]],
1888 );
1889}
1890
1891#[test]
1892fn duplicate_specialization() {
1893 check_errors(
1894 indoc! {"
1895 namespace test {
1896 operation Foo() : Unit {
1897 body ... {}
1898 body ... {}
1899 }
1900 }
1901 "},
1902 &expect![[r#"
1903 [
1904 DuplicateSpec(
1905 Span {
1906 lo: 54,
1907 hi: 65,
1908 },
1909 ),
1910 DuplicateSpec(
1911 Span {
1912 lo: 74,
1913 hi: 85,
1914 },
1915 ),
1916 ]
1917 "#]],
1918 );
1919}
1920
1921#[test]
1922fn duplicate_specialization_with_gen() {
1923 check_errors(
1924 indoc! {"
1925 namespace test {
1926 operation Foo() : Unit {
1927 body ... {}
1928 body auto;
1929 body intrinsic;
1930 }
1931 }
1932 "},
1933 &expect![[r#"
1934 [
1935 DuplicateSpec(
1936 Span {
1937 lo: 54,
1938 hi: 65,
1939 },
1940 ),
1941 DuplicateSpec(
1942 Span {
1943 lo: 74,
1944 hi: 84,
1945 },
1946 ),
1947 DuplicateSpec(
1948 Span {
1949 lo: 93,
1950 hi: 108,
1951 },
1952 ),
1953 ]
1954 "#]],
1955 );
1956}
1957
1958#[test]
1959fn partial_app_unknown_callable() {
1960 check_hir(
1961 indoc! {"
1962 namespace A {
1963 function Foo() : () { let f = Unknown(true, _, _); }
1964 }
1965 "},
1966 &expect![[r#"
1967 Package:
1968 Item 0 [0-72] (Public):
1969 Namespace (Ident 14 [10-11] "A"): Item 1
1970 Item 1 [18-70] (Internal):
1971 Parent: 0
1972 Callable 0 [18-70] (function):
1973 name: Ident 1 [27-30] "Foo"
1974 input: Pat 2 [30-32] [Type Unit]: Unit
1975 output: Unit
1976 functors: empty set
1977 body: SpecDecl 3 [18-70]: Impl:
1978 Block 4 [38-70] [Type Unit]:
1979 Stmt 5 [40-68]: Local (Immutable):
1980 Pat 6 [44-45] [Type ?3]: Bind: Ident 7 [44-45] "f"
1981 Expr 8 [48-67] [Type ?3]: Call:
1982 Expr 9 [48-55] [Type ?]: Var: Err
1983 Expr 10 [55-67] [Type (Bool, ?1, ?2)]: Tuple:
1984 Expr 11 [56-60] [Type Bool]: Lit: Bool(true)
1985 Expr 12 [62-63] [Type ?1]: Hole
1986 Expr 13 [65-66] [Type ?2]: Hole
1987 adj: <none>
1988 ctl: <none>
1989 ctl-adj: <none>"#]],
1990 );
1991}
1992
1993#[test]
1994fn partial_app_too_many_args() {
1995 check_hir(
1996 indoc! {"
1997 namespace A {
1998 function Foo(x : Int) : Int { x }
1999 function Bar() : () { let f = Foo(1, _, _); }
2000 }
2001 "},
2002 &expect![[r#"
2003 Package:
2004 Item 0 [0-103] (Public):
2005 Namespace (Ident 22 [10-11] "A"): Item 1, Item 2
2006 Item 1 [18-51] (Internal):
2007 Parent: 0
2008 Callable 0 [18-51] (function):
2009 name: Ident 1 [27-30] "Foo"
2010 input: Pat 2 [31-38] [Type Int]: Bind: Ident 3 [31-32] "x"
2011 output: Int
2012 functors: empty set
2013 body: SpecDecl 4 [18-51]: Impl:
2014 Block 5 [46-51] [Type Int]:
2015 Stmt 6 [48-49]: Expr: Expr 7 [48-49] [Type Int]: Var: Local 3
2016 adj: <none>
2017 ctl: <none>
2018 ctl-adj: <none>
2019 Item 2 [56-101] (Internal):
2020 Parent: 0
2021 Callable 8 [56-101] (function):
2022 name: Ident 9 [65-68] "Bar"
2023 input: Pat 10 [68-70] [Type Unit]: Unit
2024 output: Unit
2025 functors: empty set
2026 body: SpecDecl 11 [56-101]: Impl:
2027 Block 12 [76-101] [Type Unit]:
2028 Stmt 13 [78-99]: Local (Immutable):
2029 Pat 14 [82-83] [Type Int]: Bind: Ident 15 [82-83] "f"
2030 Expr 16 [86-98] [Type Int]: Call:
2031 Expr 17 [86-89] [Type (Int -> Int)]: Var: Item 1 (Package 1)
2032 Expr 18 [89-98] [Type (Int, ?1, ?2)]: Tuple:
2033 Expr 19 [90-91] [Type Int]: Lit: Int(1)
2034 Expr 20 [93-94] [Type ?1]: Hole
2035 Expr 21 [96-97] [Type ?2]: Hole
2036 adj: <none>
2037 ctl: <none>
2038 ctl-adj: <none>"#]],
2039 );
2040}
2041
2042#[test]
2043fn partial_app_bound_to_non_arrow_ty() {
2044 check_hir(
2045 indoc! {"
2046 namespace A {
2047 function Foo(x : Int, y : Int) : Int { x + y }
2048 function Bar() : () {
2049 let f : Int = Foo(1, _);
2050 }
2051 }
2052 "},
2053 &expect![[r#"
2054 Package:
2055 Item 0 [0-131] (Public):
2056 Namespace (Ident 45 [10-11] "A"): Item 1, Item 2
2057 Item 1 [18-64] (Internal):
2058 Parent: 0
2059 Callable 0 [18-64] (function):
2060 name: Ident 1 [27-30] "Foo"
2061 input: Pat 2 [30-48] [Type (Int, Int)]: Tuple:
2062 Pat 3 [31-38] [Type Int]: Bind: Ident 4 [31-32] "x"
2063 Pat 5 [40-47] [Type Int]: Bind: Ident 6 [40-41] "y"
2064 output: Int
2065 functors: empty set
2066 body: SpecDecl 7 [18-64]: Impl:
2067 Block 8 [55-64] [Type Int]:
2068 Stmt 9 [57-62]: Expr: Expr 10 [57-62] [Type Int]: BinOp (Add):
2069 Expr 11 [57-58] [Type Int]: Var: Local 4
2070 Expr 12 [61-62] [Type Int]: Var: Local 6
2071 adj: <none>
2072 ctl: <none>
2073 ctl-adj: <none>
2074 Item 2 [69-129] (Internal):
2075 Parent: 0
2076 Callable 13 [69-129] (function):
2077 name: Ident 14 [78-81] "Bar"
2078 input: Pat 15 [81-83] [Type Unit]: Unit
2079 output: Unit
2080 functors: empty set
2081 body: SpecDecl 16 [69-129]: Impl:
2082 Block 17 [89-129] [Type Unit]:
2083 Stmt 18 [99-123]: Local (Immutable):
2084 Pat 19 [103-110] [Type Int]: Bind: Ident 20 [103-104] "f"
2085 Expr 21 [113-122] [Type (Int -> Int)]: Expr Block: Block 42 [113-122] [Type (Int -> Int)]:
2086 Stmt 27 [117-118]: Local (Immutable):
2087 Pat 26 [117-118] [Type Int]: Bind: Ident 24 [117-118] "arg"
2088 Expr 23 [117-118] [Type Int]: Lit: Int(1)
2089 Stmt 43 [113-122]: Expr: Expr 44 [113-122] [Type (Int -> Int)]: Closure([24], 3)
2090 adj: <none>
2091 ctl: <none>
2092 ctl-adj: <none>
2093 Item 3 [113-122] (Internal):
2094 Parent: 2
2095 Callable 37 [113-122] (function):
2096 name: Ident 38 [113-122] "<lambda>"
2097 input: Pat 35 [113-122] [Type (Int, Int)]: Tuple:
2098 Pat 36 [117-118] [Type Int]: Bind: Ident 34 [117-118] "arg"
2099 Pat 30 [120-121] [Type Int]: Bind: Ident 29 [120-121] "hole"
2100 output: Int
2101 functors: empty set
2102 body: SpecDecl 39 [113-122]: Impl:
2103 Block 40 [113-122] [Type Int]:
2104 Stmt 41 [113-122]: Expr: Expr 33 [113-122] [Type Int]: Call:
2105 Expr 22 [113-116] [Type ((Int, Int) -> Int)]: Var: Item 1 (Package 1)
2106 Expr 32 [116-122] [Type (Int, Int)]: Tuple:
2107 Expr 25 [117-118] [Type Int]: Var: Local 34
2108 Expr 31 [120-121] [Type Int]: Var: Local 29
2109 adj: <none>
2110 ctl: <none>
2111 ctl-adj: <none>"#]],
2112 );
2113}
2114
2115#[test]
2116fn partial_app_hole_as_callee() {
2117 check_hir(
2118 indoc! {"
2119 namespace A {
2120 @EntryPoint()
2121 operation Main() : Result[] {
2122 let f = _(_);
2123 let res = f(4);
2124 return [res];
2125 }
2126 }
2127 "},
2128 &expect![[r#"
2129 Package:
2130 Item 0 [0-141] (Public):
2131 Namespace (Ident 21 [10-11] "A"): Item 1
2132 Item 1 [18-139] (Internal):
2133 Parent: 0
2134 EntryPoint
2135 Callable 0 [36-139] (operation):
2136 name: Ident 1 [46-50] "Main"
2137 input: Pat 2 [50-52] [Type Unit]: Unit
2138 output: Result[]
2139 functors: empty set
2140 body: SpecDecl 3 [36-139]: Impl:
2141 Block 4 [64-139] [Type Result[]]:
2142 Stmt 5 [74-87]: Local (Immutable):
2143 Pat 6 [78-79] [Type ?3]: Bind: Ident 7 [78-79] "f"
2144 Expr 8 [82-86] [Type ?3]: Call:
2145 Expr 9 [82-83] [Type ?1]: Hole
2146 Expr 10 [84-85] [Type ?2]: Hole
2147 Stmt 11 [96-111]: Local (Immutable):
2148 Pat 12 [100-103] [Type Result]: Bind: Ident 13 [100-103] "res"
2149 Expr 14 [106-110] [Type Result]: Call:
2150 Expr 15 [106-107] [Type ?3]: Var: Local 7
2151 Expr 16 [108-109] [Type Int]: Lit: Int(4)
2152 Stmt 17 [120-133]: Semi: Expr 18 [120-132] [Type Unit]: Return: Expr 19 [127-132] [Type Result[]]: Array:
2153 Expr 20 [128-131] [Type Result]: Var: Local 13
2154 adj: <none>
2155 ctl: <none>
2156 ctl-adj: <none>"#]],
2157 );
2158}
2159
2160#[test]
2161fn invalid_elided() {
2162 check_errors(
2163 indoc! {r#"
2164 namespace input {
2165 operation Foo() : Unit {
2166 let ... = 3;
2167 }
2168 }
2169 "#},
2170 &expect![[r#"
2171 [
2172 InvalidElidedPat(
2173 Span {
2174 lo: 59,
2175 hi: 62,
2176 },
2177 ),
2178 ]
2179 "#]],
2180 );
2181}
2182
2183#[test]
2184fn invalid_spec_pat() {
2185 check_errors(
2186 indoc! {r#"
2187 namespace input {
2188 operation Foo() : Unit is Ctl {
2189 body bar {}
2190 controlled (foo, bar) {}
2191 }
2192 }
2193 "#},
2194 &expect![[r#"
2195 [
2196 InvalidSpecPat(
2197 Span {
2198 lo: 67,
2199 hi: 70,
2200 },
2201 ),
2202 InvalidSpecPat(
2203 Span {
2204 lo: 93,
2205 hi: 103,
2206 },
2207 ),
2208 ]
2209 "#]],
2210 );
2211}
2212
2213#[test]
2214fn test_measurement_attr_on_function_issues_error() {
2215 check_errors(
2216 indoc! {r#"
2217 namespace Test {
2218 @Measurement()
2219 function Foo(q: Qubit) : Result {
2220 body intrinsic;
2221 }
2222 }
2223 "#},
2224 &expect![[r#"
2225 [
2226 InvalidAttrOnFunction(
2227 "Measurement",
2228 Span {
2229 lo: 49,
2230 hi: 52,
2231 },
2232 ),
2233 ]
2234 "#]],
2235 );
2236}
2237
2238#[test]
2239fn test_reset_attr_on_function_issues_error() {
2240 check_errors(
2241 indoc! {r#"
2242 namespace Test {
2243 @Reset()
2244 function Foo(q: Qubit) : Unit {
2245 body intrinsic;
2246 }
2247 }
2248 "#},
2249 &expect![[r#"
2250 [
2251 InvalidAttrOnFunction(
2252 "Reset",
2253 Span {
2254 lo: 43,
2255 hi: 46,
2256 },
2257 ),
2258 ]
2259 "#]],
2260 );
2261}
2262
2263#[test]
2264fn item_docs() {
2265 check_hir(
2266 "/// This is a namespace.
2267 namespace A {
2268 /// This is a newtype.
2269 newtype Foo = ();
2270
2271 /// This is a function.
2272 function Bar() : () {}
2273
2274 /// This is an operation.
2275 operation Baz() : () {}
2276 }",
2277 &expect![[r#"
2278 Package:
2279 Item 0 [0-268] (Public):
2280 Doc:
2281 This is a namespace.
2282 Namespace (Ident 11 [43-44] "A"): Item 1, Item 2, Item 3
2283 Item 1 [59-111] (Internal):
2284 Parent: 0
2285 Doc:
2286 This is a newtype.
2287 Type (Ident 0 [102-105] "Foo"): UDT [59-111]:
2288 TyDef [108-110]: Field:
2289 type: Unit
2290 Item 2 [125-183] (Internal):
2291 Parent: 0
2292 Doc:
2293 This is a function.
2294 Callable 1 [161-183] (function):
2295 name: Ident 2 [170-173] "Bar"
2296 input: Pat 3 [173-175] [Type Unit]: Unit
2297 output: Unit
2298 functors: empty set
2299 body: SpecDecl 4 [161-183]: Impl:
2300 Block 5 [181-183]: <empty>
2301 adj: <none>
2302 ctl: <none>
2303 ctl-adj: <none>
2304 Item 3 [197-258] (Internal):
2305 Parent: 0
2306 Doc:
2307 This is an operation.
2308 Callable 6 [235-258] (operation):
2309 name: Ident 7 [245-248] "Baz"
2310 input: Pat 8 [248-250] [Type Unit]: Unit
2311 output: Unit
2312 functors: empty set
2313 body: SpecDecl 9 [235-258]: Impl:
2314 Block 10 [256-258]: <empty>
2315 adj: <none>
2316 ctl: <none>
2317 ctl-adj: <none>"#]],
2318 );
2319}
2320
2321#[test]
2322fn nested_params() {
2323 check_hir(
2324 "namespace Test { function Foo<'T>(f: 'T => ()) : () { } }",
2325 &expect![[r#"
2326 Package:
2327 Item 0 [0-57] (Public):
2328 Namespace (Ident 6 [10-14] "Test"): Item 1
2329 Item 1 [17-55] (Internal):
2330 Parent: 0
2331 Callable 0 [17-55] (function):
2332 name: Ident 1 [26-29] "Foo"
2333 generics:
2334 0: type 'T
2335 1: functor (empty set)
2336 input: Pat 2 [34-45] [Type (Param<"'T": 0> => Unit is Param<1>)]: Bind: Ident 3 [34-35] "f"
2337 output: Unit
2338 functors: empty set
2339 body: SpecDecl 4 [17-55]: Impl:
2340 Block 5 [52-55]: <empty>
2341 adj: <none>
2342 ctl: <none>
2343 ctl-adj: <none>"#]],
2344 );
2345}
2346
2347#[test]
2348fn lambda_with_invalid_free_variable() {
2349 check_hir(
2350 "namespace Test{ operation T(): Unit {body fakelocal{() => fakelocal;}}}",
2351 &expect![[r#"
2352 Package:
2353 Item 0 [0-71] (Public):
2354 Namespace (Ident 17 [10-14] "Test"): Item 1
2355 Item 1 [16-70] (Internal):
2356 Parent: 0
2357 Callable 0 [16-70] (operation):
2358 name: Ident 1 [26-27] "T"
2359 input: Pat 2 [27-29] [Type Unit]: Unit
2360 output: Unit
2361 functors: empty set
2362 body: SpecDecl 3 [37-69]: Impl:
2363 Block 4 [51-69] [Type Unit]:
2364 Stmt 5 [52-68]: Semi: Expr 6 [52-67] [Type (Unit => Unit)]: Closure([9], 2)
2365 adj: <none>
2366 ctl: <none>
2367 ctl-adj: <none>
2368 Item 2 [52-67] (Internal):
2369 Parent: 1
2370 Callable 12 [52-67] (operation):
2371 name: Ident 13 [52-67] "<lambda>"
2372 input: Pat 11 [52-67] [Type (Unit,)]: Tuple:
2373 Pat 7 [52-54] [Type Unit]: Unit
2374 output: Unit
2375 functors: empty set
2376 body: SpecDecl 14 [58-67]: Impl:
2377 Block 15 [58-67] [Type Unit]:
2378 Stmt 16 [58-67]: Expr: Expr 8 [58-67] [Type Unit]: Var: Local 10
2379 adj: <none>
2380 ctl: <none>
2381 ctl-adj: <none>"#]],
2382 );
2383}
2384
2385#[test]
2386fn lambda_with_explicit_return_should_have_non_unit_output_type() {
2387 check_hir(
2388 "function Foo(): Unit { let f = i -> return i + 1;}",
2389 &expect![[r#"
2390 Package:
2391 Item 0 [0-50] (Public):
2392 Namespace (Ident 21 [0-50] "test"): Item 1
2393 Item 1 [0-50] (Internal):
2394 Parent: 0
2395 Callable 0 [0-50] (function):
2396 name: Ident 1 [9-12] "Foo"
2397 input: Pat 2 [12-14] [Type Unit]: Unit
2398 output: Unit
2399 functors: empty set
2400 body: SpecDecl 3 [0-50]: Impl:
2401 Block 4 [21-50] [Type Unit]:
2402 Stmt 5 [23-49]: Local (Immutable):
2403 Pat 6 [27-28] [Type (Int -> Int)]: Bind: Ident 7 [27-28] "f"
2404 Expr 8 [31-48] [Type (Int -> Int)]: Closure([], 2)
2405 adj: <none>
2406 ctl: <none>
2407 ctl-adj: <none>
2408 Item 2 [31-48] (Internal):
2409 Parent: 1
2410 Callable 16 [31-48] (function):
2411 name: Ident 17 [31-48] "<lambda>"
2412 input: Pat 15 [31-48] [Type (Int,)]: Tuple:
2413 Pat 9 [31-32] [Type Int]: Bind: Ident 10 [31-32] "i"
2414 output: Int
2415 functors: empty set
2416 body: SpecDecl 18 [36-48]: Impl:
2417 Block 19 [36-48] [Type Int]:
2418 Stmt 20 [36-48]: Expr: Expr 11 [36-48] [Type Int]: Return: Expr 12 [43-48] [Type Int]: BinOp (Add):
2419 Expr 13 [43-44] [Type Int]: Var: Local 10
2420 Expr 14 [47-48] [Type Int]: Lit: Int(1)
2421 adj: <none>
2422 ctl: <none>
2423 ctl-adj: <none>"#]],
2424 );
2425}
2426
2427#[test]
2428fn lambda_with_implicit_return_should_have_non_unit_output_type() {
2429 check_hir(
2430 "function Foo(): Unit { let f = i -> i + 1}",
2431 &expect![[r#"
2432 Package:
2433 Item 0 [0-42] (Public):
2434 Namespace (Ident 20 [0-42] "test"): Item 1
2435 Item 1 [0-42] (Internal):
2436 Parent: 0
2437 Callable 0 [0-42] (function):
2438 name: Ident 1 [9-12] "Foo"
2439 input: Pat 2 [12-14] [Type Unit]: Unit
2440 output: Unit
2441 functors: empty set
2442 body: SpecDecl 3 [0-42]: Impl:
2443 Block 4 [21-42] [Type Unit]:
2444 Stmt 5 [23-41]: Local (Immutable):
2445 Pat 6 [27-28] [Type (Int -> Int)]: Bind: Ident 7 [27-28] "f"
2446 Expr 8 [31-41] [Type (Int -> Int)]: Closure([], 2)
2447 adj: <none>
2448 ctl: <none>
2449 ctl-adj: <none>
2450 Item 2 [31-41] (Internal):
2451 Parent: 1
2452 Callable 15 [31-41] (function):
2453 name: Ident 16 [31-41] "<lambda>"
2454 input: Pat 14 [31-41] [Type (Int,)]: Tuple:
2455 Pat 9 [31-32] [Type Int]: Bind: Ident 10 [31-32] "i"
2456 output: Int
2457 functors: empty set
2458 body: SpecDecl 17 [36-41]: Impl:
2459 Block 18 [36-41] [Type Int]:
2460 Stmt 19 [36-41]: Expr: Expr 11 [36-41] [Type Int]: BinOp (Add):
2461 Expr 12 [36-37] [Type Int]: Var: Local 10
2462 Expr 13 [40-41] [Type Int]: Lit: Int(1)
2463 adj: <none>
2464 ctl: <none>
2465 ctl-adj: <none>"#]],
2466 );
2467}
2468
2469#[test]
2470fn duplicate_commas_in_tydef() {
2471 check_hir(
2472 indoc! {r#"
2473 namespace test {
2474 newtype Foo = (Int,,);
2475 }
2476 "#},
2477 &expect![[r#"
2478 Package:
2479 Item 0 [0-45] (Public):
2480 Namespace (Ident 1 [10-14] "test"): Item 1
2481 Item 1 [21-43] (Internal):
2482 Parent: 0
2483 Type (Ident 0 [29-32] "Foo"): UDT [21-43]:
2484 TyDef [35-42]: Tuple:
2485 TyDef [36-39]: Field:
2486 type: Int
2487 TyDef [40-40]: Field:
2488 type: ?"#]],
2489 );
2490}
2491
2492#[test]
2493fn duplicate_commas_in_generics() {
2494 check_hir(
2495 indoc! {r#"
2496 namespace test {
2497 function Foo<'T,,>(x : 'T) : Unit {}
2498 }
2499 "#},
2500 &expect![[r#"
2501 Package:
2502 Item 0 [0-59] (Public):
2503 Namespace (Ident 6 [10-14] "test"): Item 1
2504 Item 1 [21-57] (Internal):
2505 Parent: 0
2506 Callable 0 [21-57] (function):
2507 name: Ident 1 [30-33] "Foo"
2508 generics:
2509 0: type 'T
2510 1: type
2511 input: Pat 2 [40-46] [Type Param<"'T": 0>]: Bind: Ident 3 [40-41] "x"
2512 output: Unit
2513 functors: empty set
2514 body: SpecDecl 4 [21-57]: Impl:
2515 Block 5 [55-57]: <empty>
2516 adj: <none>
2517 ctl: <none>
2518 ctl-adj: <none>"#]],
2519 );
2520}
2521
2522#[test]
2523fn duplicate_commas_in_pat() {
2524 check_hir(
2525 indoc! {r#"
2526 namespace test {
2527 operation Foo() : Unit {
2528 let (x,,) = (1, 2);
2529 }
2530 }"#},
2531 &expect![[r#"
2532 Package:
2533 Item 0 [0-81] (Public):
2534 Namespace (Ident 13 [10-14] "test"): Item 1
2535 Item 1 [21-79] (Internal):
2536 Parent: 0
2537 Callable 0 [21-79] (operation):
2538 name: Ident 1 [31-34] "Foo"
2539 input: Pat 2 [34-36] [Type Unit]: Unit
2540 output: Unit
2541 functors: empty set
2542 body: SpecDecl 3 [21-79]: Impl:
2543 Block 4 [44-79] [Type Unit]:
2544 Stmt 5 [54-73]: Local (Immutable):
2545 Pat 6 [58-63] [Type (Int, ?)]: Tuple:
2546 Pat 7 [59-60] [Type Int]: Bind: Ident 8 [59-60] "x"
2547 Pat 9 [61-61] [Type ?]: Err
2548 Expr 10 [66-72] [Type (Int, Int)]: Tuple:
2549 Expr 11 [67-68] [Type Int]: Lit: Int(1)
2550 Expr 12 [70-71] [Type Int]: Lit: Int(2)
2551 adj: <none>
2552 ctl: <none>
2553 ctl-adj: <none>"#]],
2554 );
2555}
2556
2557#[test]
2558fn duplicate_commas_in_tuple() {
2559 check_hir(
2560 indoc! {r#"
2561 namespace test {
2562 operation Foo() : Unit {
2563 let x = (1,,3);
2564 }
2565 }"#},
2566 &expect![[r#"
2567 Package:
2568 Item 0 [0-77] (Public):
2569 Namespace (Ident 12 [10-14] "test"): Item 1
2570 Item 1 [21-75] (Internal):
2571 Parent: 0
2572 Callable 0 [21-75] (operation):
2573 name: Ident 1 [31-34] "Foo"
2574 input: Pat 2 [34-36] [Type Unit]: Unit
2575 output: Unit
2576 functors: empty set
2577 body: SpecDecl 3 [21-75]: Impl:
2578 Block 4 [44-75] [Type Unit]:
2579 Stmt 5 [54-69]: Local (Immutable):
2580 Pat 6 [58-59] [Type (Int, ?, Int)]: Bind: Ident 7 [58-59] "x"
2581 Expr 8 [62-68] [Type (Int, ?, Int)]: Tuple:
2582 Expr 9 [63-64] [Type Int]: Lit: Int(1)
2583 Expr 10 [65-65] [Type ?]: Err
2584 Expr 11 [66-67] [Type Int]: Lit: Int(3)
2585 adj: <none>
2586 ctl: <none>
2587 ctl-adj: <none>"#]],
2588 );
2589}
2590
2591#[test]
2592fn duplicate_commas_in_arg_tuple() {
2593 check_hir(
2594 indoc! {r#"
2595 namespace test {
2596 operation Foo(a : Int, b : Int, c : Int) : Int {
2597 Foo(a,,c)
2598 }
2599 }"#},
2600 &expect![[r#"
2601 Package:
2602 Item 0 [0-95] (Public):
2603 Namespace (Ident 18 [10-14] "test"): Item 1
2604 Item 1 [21-93] (Internal):
2605 Parent: 0
2606 Callable 0 [21-93] (operation):
2607 name: Ident 1 [31-34] "Foo"
2608 input: Pat 2 [34-61] [Type (Int, Int, Int)]: Tuple:
2609 Pat 3 [35-42] [Type Int]: Bind: Ident 4 [35-36] "a"
2610 Pat 5 [44-51] [Type Int]: Bind: Ident 6 [44-45] "b"
2611 Pat 7 [53-60] [Type Int]: Bind: Ident 8 [53-54] "c"
2612 output: Int
2613 functors: empty set
2614 body: SpecDecl 9 [21-93]: Impl:
2615 Block 10 [68-93] [Type Int]:
2616 Stmt 11 [78-87]: Expr: Expr 12 [78-87] [Type Int]: Call:
2617 Expr 13 [78-81] [Type ((Int, Int, Int) => Int)]: Var: Item 1 (Package 1)
2618 Expr 14 [81-87] [Type (Int, ?, Int)]: Tuple:
2619 Expr 15 [82-83] [Type Int]: Var: Local 4
2620 Expr 16 [84-84] [Type ?]: Err
2621 Expr 17 [85-86] [Type Int]: Var: Local 8
2622 adj: <none>
2623 ctl: <none>
2624 ctl-adj: <none>"#]],
2625 );
2626}
2627
2628#[test]
2629fn ignore_item_in_attribute() {
2630 check_hir(
2631 "namespace Test {
2632 @Attr{function Bar() : Unit { Bar }}
2633 function Foo() : Unit {}
2634 }",
2635 &expect![[r#"
2636 Package:
2637 Item 0 [0-112] (Public):
2638 Namespace (Ident 5 [10-14] "Test"): Item 1
2639 Item 1 [29-102] (Internal):
2640 Parent: 0
2641 Callable 0 [78-102] (function):
2642 name: Ident 1 [87-90] "Foo"
2643 input: Pat 2 [90-92] [Type Unit]: Unit
2644 output: Unit
2645 functors: empty set
2646 body: SpecDecl 3 [78-102]: Impl:
2647 Block 4 [100-102]: <empty>
2648 adj: <none>
2649 ctl: <none>
2650 ctl-adj: <none>"#]],
2651 );
2652}
2653
2654#[test]
2655fn self_export_makes_callable_public() {
2656 // Export item should vanish during lowering, and the original
2657 // callable should be marked public
2658 check_hir(
2659 indoc! {"
2660 namespace Test {
2661 function Length() : Int { 42 }
2662 export Length;
2663 }
2664 "},
2665 &expect![[r#"
2666 Package:
2667 Item 0 [0-72] (Public):
2668 Namespace (Ident 8 [10-14] "Test"): Item 1
2669 Item 1 [21-51] (Public):
2670 Parent: 0
2671 Callable 0 [21-51] (function):
2672 name: Ident 1 [30-36] "Length"
2673 input: Pat 2 [36-38] [Type Unit]: Unit
2674 output: Int
2675 functors: empty set
2676 body: SpecDecl 3 [21-51]: Impl:
2677 Block 4 [45-51] [Type Int]:
2678 Stmt 5 [47-49]: Expr: Expr 6 [47-49] [Type Int]: Lit: Int(42)
2679 adj: <none>
2680 ctl: <none>
2681 ctl-adj: <none>"#]],
2682 );
2683}
2684
2685#[test]
2686fn self_export_makes_ty_public() {
2687 // Export item should vanish during lowering, and the original
2688 // UDT should be marked public
2689 check_hir(
2690 indoc! {"
2691 namespace Foo {
2692 struct Bar { x: Int }
2693 export Bar;
2694 }
2695 "},
2696 &expect![[r#"
2697 Package:
2698 Item 0 [0-59] (Public):
2699 Namespace (Ident 2 [10-13] "Foo"): Item 1
2700 Item 1 [20-41] (Public):
2701 Parent: 0
2702 Type (Ident 0 [27-30] "Bar"): UDT [20-41]:
2703 TyDef [20-41]: Tuple:
2704 TyDef [33-39]: Field:
2705 name: x [33-34]
2706 type: Int"#]],
2707 );
2708}
2709
2710#[test]
2711fn export_in_different_namespace_creates_export_item() {
2712 // An export item should be created, and the original callable should
2713 // remain internal.
2714 check_hir(
2715 indoc! {"
2716 namespace Foo {
2717 function Bar() : Int { 1 }
2718 }
2719 namespace Test {
2720 export Foo.Bar;
2721 }
2722 "},
2723 &expect![[r#"
2724 Package:
2725 Item 0 [0-48] (Public):
2726 Namespace (Ident 7 [10-13] "Foo"): Item 1
2727 Item 1 [20-46] (Internal):
2728 Parent: 0
2729 Callable 0 [20-46] (function):
2730 name: Ident 1 [29-32] "Bar"
2731 input: Pat 2 [32-34] [Type Unit]: Unit
2732 output: Int
2733 functors: empty set
2734 body: SpecDecl 3 [20-46]: Impl:
2735 Block 4 [41-46] [Type Int]:
2736 Stmt 5 [43-44]: Expr: Expr 6 [43-44] [Type Int]: Lit: Int(1)
2737 adj: <none>
2738 ctl: <none>
2739 ctl-adj: <none>
2740 Item 2 [49-87] (Public):
2741 Namespace (Ident 9 [59-63] "Test"): Item 3
2742 Item 3 [70-85] (Public):
2743 Parent: 2
2744 Export (Ident 8 [81-84] "Bar"): Item 1 (Package 1)"#]],
2745 );
2746}
2747
2748#[test]
2749fn wildcard_import_export_in_different_namespace_creates_export_item() {
2750 // An export item should be created, and the original callable should
2751 // remain internal.
2752 check_hir(
2753 indoc! {"
2754 namespace Foo {
2755 function Bar() : Unit {}
2756 }
2757 namespace Test {
2758 import Foo.*;
2759 export Bar;
2760 function Test() : Unit {
2761 Bar();
2762 }
2763 }
2764 "},
2765 &expect![[r#"
2766 Package:
2767 Item 0 [0-46] (Public):
2768 Namespace (Ident 5 [10-13] "Foo"): Item 1
2769 Item 1 [20-44] (Internal):
2770 Parent: 0
2771 Callable 0 [20-44] (function):
2772 name: Ident 1 [29-32] "Bar"
2773 input: Pat 2 [32-34] [Type Unit]: Unit
2774 output: Unit
2775 functors: empty set
2776 body: SpecDecl 3 [20-44]: Impl:
2777 Block 4 [42-44]: <empty>
2778 adj: <none>
2779 ctl: <none>
2780 ctl-adj: <none>
2781 Item 2 [47-149] (Public):
2782 Namespace (Ident 16 [57-61] "Test"): Item 3, Item 4
2783 Item 3 [86-97] (Public):
2784 Parent: 2
2785 Export (Ident 6 [93-96] "Bar"): Item 1 (Package 1)
2786 Item 4 [102-147] (Internal):
2787 Parent: 2
2788 Callable 7 [102-147] (function):
2789 name: Ident 8 [111-115] "Test"
2790 input: Pat 9 [115-117] [Type Unit]: Unit
2791 output: Unit
2792 functors: empty set
2793 body: SpecDecl 10 [102-147]: Impl:
2794 Block 11 [125-147] [Type Unit]:
2795 Stmt 12 [135-141]: Semi: Expr 13 [135-140] [Type Unit]: Call:
2796 Expr 14 [135-138] [Type (Unit -> Unit)]: Var: Item 1 (Package 1)
2797 Expr 15 [138-140] [Type Unit]: Unit
2798 adj: <none>
2799 ctl: <none>
2800 ctl-adj: <none>"#]],
2801 );
2802}
2803
2804#[test]
2805fn aliased_export_creates_export_item() {
2806 // An export item should be created, and the original callable should
2807 // remain internal.
2808 check_hir(
2809 indoc! {"
2810 namespace Foo {
2811 function Bar() : Int { 1 }
2812 }
2813 namespace Test {
2814 export Foo.Bar as Baz;
2815 }
2816 "},
2817 &expect![[r#"
2818 Package:
2819 Item 0 [0-48] (Public):
2820 Namespace (Ident 7 [10-13] "Foo"): Item 1
2821 Item 1 [20-46] (Internal):
2822 Parent: 0
2823 Callable 0 [20-46] (function):
2824 name: Ident 1 [29-32] "Bar"
2825 input: Pat 2 [32-34] [Type Unit]: Unit
2826 output: Int
2827 functors: empty set
2828 body: SpecDecl 3 [20-46]: Impl:
2829 Block 4 [41-46] [Type Int]:
2830 Stmt 5 [43-44]: Expr: Expr 6 [43-44] [Type Int]: Lit: Int(1)
2831 adj: <none>
2832 ctl: <none>
2833 ctl-adj: <none>
2834 Item 2 [49-94] (Public):
2835 Namespace (Ident 9 [59-63] "Test"): Item 3
2836 Item 3 [70-92] (Public):
2837 Parent: 2
2838 Export (Ident 8 [88-91] "Baz"): Item 1 (Package 1)"#]],
2839 );
2840}
2841
2842#[test]
2843fn export_parent_namespace_is_err() {
2844 // A namespace that's only ever declared as a parent (e.g.
2845 // the `Parent` in `Parent.Foo`) cannot be exported since we don't
2846 // assign it an Item ID.
2847 let input = indoc! {"
2848 namespace Parent.Foo {
2849 function Bar() : Unit {}
2850 export Bar;
2851 }
2852
2853 namespace Baz {
2854 export Parent as ParentAlias;
2855 }
2856
2857 namespace Main {
2858 export Baz.ParentAlias;
2859 operation Main() : Unit {}
2860 }
2861 "};
2862 check_errors(
2863 input,
2864 &expect![[r#"
2865 [
2866 ParentNamespaceExport {
2867 span: Span {
2868 lo: 98,
2869 hi: 104,
2870 },
2871 },
2872 ParentNamespaceExport {
2873 span: Span {
2874 lo: 152,
2875 hi: 167,
2876 },
2877 },
2878 ]
2879 "#]],
2880 );
2881 check_hir(
2882 input,
2883 &expect![[r#"
2884 Package:
2885 Item 0 [0-69] (Public):
2886 Namespace ([Ident 6 [10-16] "Parent", Ident 7 [17-20] "Foo"]): Item 1
2887 Item 1 [27-51] (Public):
2888 Parent: 0
2889 Callable 0 [27-51] (function):
2890 name: Ident 1 [36-39] "Bar"
2891 input: Pat 2 [39-41] [Type Unit]: Unit
2892 output: Unit
2893 functors: empty set
2894 body: SpecDecl 3 [27-51]: Impl:
2895 Block 4 [49-51]: <empty>
2896 adj: <none>
2897 ctl: <none>
2898 ctl-adj: <none>
2899 Item 3 [71-122] (Public):
2900 Namespace (Ident 9 [81-84] "Baz"): Item 4
2901 Item 4 [91-120] (Public):
2902 Parent: 3
2903 Export (Ident 8 [108-119] "ParentAlias"): Err
2904 Item 5 [124-201] (Public):
2905 Namespace (Ident 16 [134-138] "Main"): Item 6, Item 7
2906 Item 6 [145-168] (Public):
2907 Parent: 5
2908 Export (Ident 10 [156-167] "ParentAlias"): Err
2909 Item 7 [173-199] (Internal):
2910 Parent: 5
2911 Callable 11 [173-199] (operation):
2912 name: Ident 12 [183-187] "Main"
2913 input: Pat 13 [187-189] [Type Unit]: Unit
2914 output: Unit
2915 functors: empty set
2916 body: SpecDecl 14 [173-199]: Impl:
2917 Block 15 [197-199]: <empty>
2918 adj: <none>
2919 ctl: <none>
2920 ctl-adj: <none>"#]],
2921 );
2922}
2923
2924#[test]
2925fn literal_complex_lowers_as_struct_decl() {
2926 check_hir(
2927 indoc! {"
2928 function Imaginary4() : Complex {
2929 4.0i
2930 }
2931 "},
2932 &expect![[r#"
2933 Package:
2934 Item 0 [0-44] (Public):
2935 Namespace (Ident 11 [0-44] "test"): Item 1
2936 Item 1 [0-44] (Internal):
2937 Parent: 0
2938 Callable 0 [0-44] (function):
2939 name: Ident 1 [9-19] "Imaginary4"
2940 input: Pat 2 [19-21] [Type Unit]: Unit
2941 output: UDT<"Complex": Item 3 (Package 0)>
2942 functors: empty set
2943 body: SpecDecl 3 [0-44]: Impl:
2944 Block 4 [32-44] [Type UDT<"Complex": Item 3 (Package 0)>]:
2945 Stmt 5 [38-42]: Expr: Expr 6 [38-42] [Type UDT<"Complex": Item 3 (Package 0)>]: Struct (Item 3 (Package 0)):
2946 FieldsAssign 7 [0-0]: (Path([0])) Expr 8 [0-0] [Type Double]: Lit: Double(0)
2947 FieldsAssign 9 [0-0]: (Path([1])) Expr 10 [0-0] [Type Double]: Lit: Double(4)
2948 adj: <none>
2949 ctl: <none>
2950 ctl-adj: <none>"#]],
2951 );
2952}
2953