microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-2145

Branches

Tags

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

Clone

HTTPS

Download ZIP

compiler/qsc_frontend/src/resolve/tests.rs

5315lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use super::{Error, Locals, Names, Res};
5use crate::{
6 compile,
7 resolve::{LocalKind, Resolver},
8};
9use expect_test::{expect, Expect};
10use indoc::indoc;
11use qsc_ast::ast::{Idents, Item, ItemKind, PathKind};
12use qsc_ast::{
13 assigner::Assigner as AstAssigner,
14 ast::{Ident, NodeId, Package, Path, TopLevelNode},
15 mut_visit::MutVisitor,
16 visit::{self, Visitor},
17};
18
19use qsc_data_structures::{
20 language_features::LanguageFeatures,
21 namespaces::{NamespaceId, NamespaceTreeRoot},
22 span::Span,
23 target::TargetCapabilityFlags,
24};
25use qsc_hir::assigner::Assigner as HirAssigner;
26use rustc_hash::FxHashMap;
27use std::rc::Rc;
28use std::{fmt::Write, vec};
29
30#[derive(Debug)]
31enum Change {
32 Res(Res),
33 NamespaceId(NamespaceId),
34}
35
36impl From<Res> for Change {
37 fn from(res: Res) -> Self {
38 Self::Res(res)
39 }
40}
41
42impl From<NamespaceId> for Change {
43 fn from(ns_id: NamespaceId) -> Self {
44 Self::NamespaceId(ns_id)
45 }
46}
47
48struct Renamer<'a> {
49 names: &'a Names,
50 changes: Vec<(Span, Change)>,
51 namespaces: NamespaceTreeRoot,
52 aliases: FxHashMap<Vec<Rc<str>>, NamespaceId>,
53}
54
55impl<'a> Renamer<'a> {
56 fn new(names: &'a Names, namespaces: NamespaceTreeRoot) -> Self {
57 Self {
58 names,
59 changes: Vec::new(),
60 namespaces,
61 aliases: FxHashMap::default(),
62 }
63 }
64
65 fn rename(&self, input: &mut String) {
66 for (span, change) in self.changes.iter().rev() {
67 let name = match change {
68 Change::Res(res) => Self::format_res(res),
69 Change::NamespaceId(ns_id) => format!("namespace{}", Into::<usize>::into(ns_id)),
70 };
71 input.replace_range((span.lo as usize)..(span.hi as usize), &name);
72 }
73 }
74
75 fn format_res(res: &Res) -> String {
76 match res {
77 Res::Item(item, _) => match item.package {
78 None => format!("item{}", item.item),
79 Some(package) => format!("package{package}_item{}", item.item),
80 },
81 Res::Local(node) => format!("local{node}"),
82 Res::PrimTy(prim) => format!("{prim:?}"),
83 Res::UnitTy => "Unit".to_string(),
84 Res::Param { id, .. } => format!("param{id}"),
85 Res::ExportedItem(item, _) => match item.package {
86 None => format!("exported_item{}", item.item),
87 Some(package) => format!("reexport_from_{package}:{}", item.item),
88 },
89 }
90 }
91}
92
93impl Visitor<'_> for Renamer<'_> {
94 fn visit_path(&mut self, path: &Path) {
95 if let Some(res) = self.names.get(path.id) {
96 // The whole path node can be a resolved name
97 self.changes.push((path.span, res.clone().into()));
98 return;
99 }
100
101 let ns_id = self.find_namespace_id(path);
102 if let Some(ns_id) = ns_id {
103 // The whole path can be a namespace
104 self.changes.push((path.span, ns_id.into()));
105 return;
106 }
107
108 if let Some(segments) = &path.segments {
109 // The segments part can be a namespace
110 let ns_id = self.find_namespace_id(segments);
111 if let Some(ns_id) = ns_id {
112 self.changes.push((segments.full_span(), ns_id.into()));
113 return;
114 }
115 }
116
117 // Individual ident nodes can be resolved names
118 visit::walk_path(self, path);
119 }
120
121 fn visit_idents(&mut self, idents: &[Ident]) {
122 let ns_id = self.find_namespace_id(&idents);
123 if let Some(ns_id) = ns_id {
124 self.changes.push((idents.full_span(), ns_id.into()));
125 return;
126 }
127 visit::walk_idents(self, idents);
128 }
129
130 fn visit_ident(&mut self, ident: &Ident) {
131 if let Some(res) = self.names.get(ident.id) {
132 self.changes.push((ident.span, res.clone().into()));
133 }
134 }
135
136 fn visit_item(&mut self, item: &'_ Item) {
137 match &*item.kind {
138 ItemKind::Open(PathKind::Ok(namespace), Some(alias)) => {
139 if let Some(ns_id) = self.namespaces.get_namespace_id(namespace.str_iter()) {
140 // self.changes.push((item.span, ns_id.into()));
141 self.aliases.insert(vec![alias.name.clone()], ns_id);
142 } else {
143 return;
144 }
145 }
146 ItemKind::ImportOrExport(export) => {
147 for item in export.items() {
148 let PathKind::Ok(path) = &item.path else {
149 continue;
150 };
151 if let Some(res) = self.names.get(path.id) {
152 // Path node can be a resolved name
153 self.changes.push((item.span, (res.clone()).into()));
154 } else if let Some(namespace_id) =
155 self.namespaces.get_namespace_id(path.str_iter())
156 {
157 // Path can be a namespace
158 self.changes.push((
159 if item.alias.is_some() {
160 item.span
161 } else {
162 path.span
163 },
164 namespace_id.into(),
165 ));
166 }
167 }
168 return;
169 }
170 _ => (),
171 }
172 visit::walk_item(self, item);
173 }
174}
175
176impl Renamer<'_> {
177 fn find_namespace_id(&mut self, idents: &impl Idents) -> Option<NamespaceId> {
178 let ns_id = self
179 .namespaces
180 .get_namespace_id(idents.str_iter())
181 .or_else(|| {
182 self.aliases
183 .get(&idents.rc_str_iter().cloned().collect::<Vec<_>>())
184 .copied()
185 });
186 ns_id
187 }
188}
189
190fn check(input: &str, expect: &Expect) {
191 expect.assert_eq(&resolve_names(input, TargetCapabilityFlags::all()));
192}
193
194fn check_with_capabilities(input: &str, capabilities: TargetCapabilityFlags, expect: &Expect) {
195 expect.assert_eq(&resolve_names(input, capabilities));
196}
197
198fn resolve_names(input: &str, capabilities: TargetCapabilityFlags) -> String {
199 let (package, names, _, errors, namespaces) =
200 compile(input, LanguageFeatures::default(), capabilities);
201 let mut renamer = Renamer::new(&names, namespaces);
202 renamer.visit_package(&package);
203 let mut output = input.to_string();
204 renamer.rename(&mut output);
205 if !errors.is_empty() {
206 output += "\n";
207 }
208 for error in &errors {
209 writeln!(output, "// {error:?}").expect("string should be writable");
210 }
211 output
212}
213
214fn compile(
215 input: &str,
216 language_features: LanguageFeatures,
217 capabilities: TargetCapabilityFlags,
218) -> (Package, Names, Locals, Vec<Error>, NamespaceTreeRoot) {
219 let (namespaces, parse_errors) = qsc_parse::namespaces(input, None, language_features);
220 assert!(parse_errors.is_empty(), "parse failed: {parse_errors:#?}");
221 let mut package = Package {
222 id: NodeId::default(),
223 nodes: namespaces
224 .into_iter()
225 .map(TopLevelNode::Namespace)
226 .collect::<Vec<_>>()
227 .into_boxed_slice(),
228 entry: None,
229 };
230
231 AstAssigner::new().visit_package(&mut package);
232
233 let mut cond_compile = compile::preprocess::Conditional::new(capabilities);
234 cond_compile.visit_package(&mut package);
235 let dropped_names = cond_compile.into_names();
236
237 let mut assigner = HirAssigner::new();
238 // insert the core namespace
239
240 let mut globals = super::GlobalTable::new();
241 let mut errors = globals.add_local_package(&mut assigner, &package);
242 let mut resolver = Resolver::new(globals, dropped_names);
243 resolver.bind_and_resolve_imports_and_exports(&package);
244 resolver.with(&mut assigner).visit_package(&package);
245 let (names, locals, mut resolve_errors, namespaces) = resolver.into_result();
246 errors.append(&mut resolve_errors);
247 (package, names, locals, errors, namespaces)
248}
249
250#[test]
251fn global_callable() {
252 check(
253 indoc! {"
254 namespace Foo {
255 function A() : Unit {}
256
257 function B() : Unit {
258 A();
259 }
260 }
261 "},
262 &expect![[r#"
263 namespace namespace3 {
264 function item1() : Unit {}
265
266 function item2() : Unit {
267 item1();
268 }
269 }
270 "#]],
271 );
272}
273
274#[test]
275fn global_callable_recursive() {
276 check(
277 indoc! {
278 "namespace Foo {
279 function A() : Unit {
280 A();
281 }
282 }
283 "},
284 &expect![[r#"
285 namespace namespace3 {
286 function item1() : Unit {
287 item1();
288 }
289 }
290 "#]],
291 );
292}
293
294#[test]
295fn global_callable_internal() {
296 check(
297 indoc! {"
298 namespace Foo {
299 internal function A() : Unit {}
300
301 function B() : Unit {
302 A();
303 }
304 }
305 "},
306 &expect![[r#"
307 namespace namespace3 {
308 internal function item1() : Unit {}
309
310 function item2() : Unit {
311 item1();
312 }
313 }
314 "#]],
315 );
316}
317
318#[test]
319fn global_callable_duplicate_error() {
320 check(
321 indoc! {"
322 namespace Foo {
323 function A() : Unit {}
324 operation A() : Unit {}
325 }
326 "},
327 &expect![[r#"
328 namespace namespace3 {
329 function item1() : Unit {}
330 operation item2() : Unit {}
331 }
332
333 // Duplicate("A", "Foo", Span { lo: 57, hi: 58 })
334 "#]],
335 );
336}
337
338#[test]
339fn global_path() {
340 check(
341 indoc! {"
342 namespace Foo {
343 function A() : Unit {}
344 }
345
346 namespace Bar {
347 function B() : Unit {
348 Foo.A();
349 }
350 }
351 "},
352 &expect![[r#"
353 namespace namespace3 {
354 function item1() : Unit {}
355 }
356
357 namespace namespace4 {
358 function item3() : Unit {
359 item1();
360 }
361 }
362 "#]],
363 );
364}
365
366#[test]
367fn open_namespace() {
368 check(
369 indoc! {"
370 namespace Foo {
371 function A() : Unit {}
372 }
373
374 namespace Bar {
375 open Foo;
376
377 function B() : Unit {
378 A();
379 }
380 }
381 "},
382 &expect![[r#"
383 namespace namespace3 {
384 function item1() : Unit {}
385 }
386
387 namespace namespace4 {
388 open namespace3;
389
390 function item3() : Unit {
391 item1();
392 }
393 }
394 "#]],
395 );
396}
397
398#[test]
399fn open_alias() {
400 check(
401 indoc! {"
402 namespace Foo {
403 function A() : Unit {}
404 }
405
406 namespace Bar {
407 open Foo as F;
408
409 function B() : Unit {
410 F.A();
411 }
412 }
413 "},
414 &expect![[r#"
415 namespace namespace3 {
416 function item1() : Unit {}
417 }
418
419 namespace namespace4 {
420 open namespace3 as F;
421
422 function item3() : Unit {
423 item1();
424 }
425 }
426 "#]],
427 );
428}
429
430#[test]
431fn prelude_callable() {
432 check(
433 indoc! {"
434 namespace Std.Core {
435 function A() : Unit {}
436 }
437
438 namespace Foo {
439 function B() : Unit {
440 A();
441 }
442 }
443 "},
444 &expect![[r#"
445 namespace namespace2 {
446 function item1() : Unit {}
447 }
448
449 namespace namespace3 {
450 function item3() : Unit {
451 item1();
452 }
453 }
454 "#]],
455 );
456}
457
458#[test]
459fn parent_namespace_shadows_prelude() {
460 check(
461 indoc! {"
462 namespace Std.Core {
463 function A() : Unit {}
464 }
465
466 namespace Foo {
467 function A() : Unit {}
468
469 function B() : Unit {
470 A();
471 }
472 }
473 "},
474 &expect![[r#"
475 namespace namespace2 {
476 function item1() : Unit {}
477 }
478
479 namespace namespace3 {
480 function item3() : Unit {}
481
482 function item4() : Unit {
483 item3();
484 }
485 }
486 "#]],
487 );
488}
489
490#[test]
491fn open_shadows_prelude() {
492 check(
493 indoc! {"
494 namespace Std.Core {
495 function A() : Unit {}
496 }
497
498 namespace Foo {
499 function A() : Unit {}
500 }
501
502 namespace Bar {
503 open Foo;
504
505 function B() : Unit {
506 A();
507 }
508 }
509 "},
510 &expect![[r#"
511 namespace namespace2 {
512 function item1() : Unit {}
513 }
514
515 namespace namespace3 {
516 function item3() : Unit {}
517 }
518
519 namespace namespace4 {
520 open namespace3;
521
522 function item5() : Unit {
523 item3();
524 }
525 }
526 "#]],
527 );
528}
529
530#[test]
531fn ambiguous_prelude() {
532 check(
533 indoc! {"
534 namespace Std.Canon {
535 function A() : Unit {}
536 }
537
538 namespace Std.Measurement {
539 function A() : Unit {}
540 }
541
542 namespace Foo {
543 function B() : Unit {
544 A();
545 }
546 }
547 "},
548 &expect![[r#"
549 namespace namespace3 {
550 function item1() : Unit {}
551 }
552
553 namespace namespace4 {
554 function item3() : Unit {}
555 }
556
557 namespace namespace5 {
558 function item5() : Unit {
559 A();
560 }
561 }
562
563 // AmbiguousPrelude { name: "A", candidate_a: "Std.Canon", candidate_b: "Std.Measurement", span: Span { lo: 160, hi: 161 } }
564 "#]],
565 );
566}
567
568#[test]
569fn local_var() {
570 check(
571 indoc! {"
572 namespace Foo {
573 function A() : Int {
574 let x = 0;
575 x
576 }
577 }
578 "},
579 &expect![[r#"
580 namespace namespace3 {
581 function item1() : Int {
582 let local13 = 0;
583 local13
584 }
585 }
586 "#]],
587 );
588}
589
590#[test]
591fn shadow_local() {
592 check(
593 indoc! {"
594 namespace Foo {
595 function A() : Int {
596 let x = 0;
597 let y = {
598 let x = 1;
599 x
600 };
601 x + y
602 }
603 }
604 "},
605 &expect![[r#"
606 namespace namespace3 {
607 function item1() : Int {
608 let local13 = 0;
609 let local17 = {
610 let local22 = 1;
611 local22
612 };
613 local13 + local17
614 }
615 }
616 "#]],
617 );
618}
619
620#[test]
621fn callable_param() {
622 check(
623 indoc! {"
624 namespace Foo {
625 function A(x : Int) : Int {
626 x
627 }
628 }
629 "},
630 &expect![[r#"
631 namespace namespace3 {
632 function item1(local8 : Int) : Int {
633 local8
634 }
635 }
636 "#]],
637 );
638}
639
640#[test]
641fn spec_param() {
642 check(
643 indoc! {"
644 namespace Foo {
645 operation A(q : Qubit) : (Qubit[], Qubit) {
646 controlled (cs, ...) {
647 (cs, q)
648 }
649 }
650 }
651 "},
652 &expect![[r#"
653 namespace namespace3 {
654 operation item1(local8 : Qubit) : (Qubit[], Qubit) {
655 controlled (local23, ...) {
656 (local23, local8)
657 }
658 }
659 }
660 "#]],
661 );
662}
663
664#[test]
665fn spec_param_shadow_disallowed() {
666 check(
667 indoc! {"
668 namespace Foo {
669 operation A(qs : Qubit[]) : Qubit[] {
670 controlled (qs, ...) {
671 qs
672 }
673 body ... {
674 qs
675 }
676 }
677 }
678 "},
679 &expect![[r#"
680 namespace namespace3 {
681 operation item1(local8 : Qubit[]) : Qubit[] {
682 controlled (local20, ...) {
683 local20
684 }
685 body ... {
686 local8
687 }
688 }
689 }
690
691 // DuplicateBinding("qs", Span { lo: 78, hi: 80 })
692 "#]],
693 );
694}
695
696#[test]
697fn local_shadows_global() {
698 check(
699 indoc! {"
700 namespace Foo {
701 function x() : Unit {}
702
703 function y() : Int {
704 x();
705 let x = 1;
706 x
707 }
708 }
709 "},
710 &expect![[r#"
711 namespace namespace3 {
712 function item1() : Unit {}
713
714 function item2() : Int {
715 item1();
716 let local27 = 1;
717 local27
718 }
719 }
720 "#]],
721 );
722}
723
724#[test]
725fn shadow_same_block() {
726 check(
727 indoc! {"
728 namespace Foo {
729 function A() : Int {
730 let x = 0;
731 let x = x + 1;
732 x
733 }
734 }
735 "},
736 &expect![[r#"
737 namespace namespace3 {
738 function item1() : Int {
739 let local13 = 0;
740 let local17 = local13 + 1;
741 local17
742 }
743 }
744 "#]],
745 );
746}
747
748#[test]
749fn parent_namespace_shadows_open() {
750 check(
751 indoc! {"
752 namespace Foo {
753 function A() : Unit {}
754 }
755
756 namespace Bar {
757 open Foo;
758
759 function A() : Unit {}
760
761 function B() : Unit {
762 A();
763 }
764 }
765 "},
766 &expect![[r#"
767 namespace namespace3 {
768 function item1() : Unit {}
769 }
770
771 namespace namespace4 {
772 open namespace3;
773
774 function item3() : Unit {}
775
776 function item4() : Unit {
777 item3();
778 }
779 }
780 "#]],
781 );
782}
783
784#[test]
785fn open_alias_shadows_global() {
786 check(
787 indoc! {"
788 namespace Foo {
789 function A() : Unit {}
790 }
791
792 namespace Bar {
793 function A() : Unit {}
794 }
795
796 namespace Baz {
797 open Foo as Bar;
798
799 function B() : Unit {
800 Bar.A();
801 }
802 }
803 "},
804 &expect![[r#"
805 namespace namespace3 {
806 function item1() : Unit {}
807 }
808
809 namespace namespace4 {
810 function item3() : Unit {}
811 }
812
813 namespace namespace5 {
814 open namespace3 as Bar;
815
816 function item5() : Unit {
817 item1();
818 }
819 }
820 "#]],
821 );
822}
823
824#[test]
825fn shadowing_disallowed_within_parameters() {
826 check(
827 indoc! {"
828 namespace Test {
829 operation Foo(x: Int, y: Double, x: Bool) : Unit {}
830 }
831 "},
832 &expect![[r#"
833 namespace namespace3 {
834 operation item1(local8: Int, local13: Double, local18: Bool) : Unit {}
835 }
836
837 // DuplicateBinding("x", Span { lo: 54, hi: 55 })
838 "#]],
839 );
840}
841
842#[test]
843fn shadowing_disallowed_within_local_binding() {
844 check(
845 indoc! {"
846 namespace Test {
847 operation Foo() : Unit {
848 let (first, second, first) = (1, 2, 3);
849 }
850 }
851 "},
852 &expect![[r#"
853 namespace namespace3 {
854 operation item1() : Unit {
855 let (local14, local16, local18) = (1, 2, 3);
856 }
857 }
858
859 // DuplicateBinding("first", Span { lo: 74, hi: 79 })
860 "#]],
861 );
862}
863
864#[test]
865fn shadowing_disallowed_within_for_loop() {
866 check(
867 indoc! {"
868 namespace Test {
869 operation Foo() : Unit {
870 for (key, val, key) in [(1, 1, 1)] {}
871 }
872 }
873 "},
874 &expect![[r#"
875 namespace namespace3 {
876 operation item1() : Unit {
877 for (local15, local17, local19) in [(1, 1, 1)] {}
878 }
879 }
880
881 // DuplicateBinding("key", Span { lo: 69, hi: 72 })
882 "#]],
883 );
884}
885
886#[test]
887fn shadowing_disallowed_within_lambda_param() {
888 check(
889 indoc! {"
890 namespace Test {
891 operation Foo() : Unit {
892 let f = (x, y, x) -> x + y + 1;
893 }
894 }
895 "},
896 &expect![[r#"
897 namespace namespace3 {
898 operation item1() : Unit {
899 let local13 = (local17, local19, local21) -> local21 + local19 + 1;
900 }
901 }
902
903 // DuplicateBinding("x", Span { lo: 69, hi: 70 })
904 "#]],
905 );
906}
907
908#[test]
909fn merged_aliases() {
910 check(
911 indoc! {"
912 namespace Foo {
913 function A() : Unit {}
914 }
915
916 namespace Bar {
917 function B() : Unit {}
918 }
919
920 namespace Baz {
921 open Foo as Alias;
922 open Bar as Alias;
923
924 function C() : Unit {
925 Alias.A();
926 Alias.B();
927 }
928 }
929 "},
930 &expect![[r#"
931 namespace namespace3 {
932 function item1() : Unit {}
933 }
934
935 namespace namespace4 {
936 function item3() : Unit {}
937 }
938
939 namespace namespace5 {
940 open namespace3 as Alias;
941 open namespace4 as Alias;
942
943 function item5() : Unit {
944 item1();
945 item3();
946 }
947 }
948 "#]],
949 );
950}
951
952#[test]
953fn ty_decl() {
954 check(
955 indoc! {"
956 namespace Foo {
957 newtype A = Unit;
958 function B(a : A) : Unit {}
959 }
960 "},
961 &expect![[r#"
962 namespace namespace3 {
963 newtype item1 = Unit;
964 function item2(local14 : item1) : Unit {}
965 }
966 "#]],
967 );
968}
969
970#[test]
971fn struct_decl() {
972 check(
973 indoc! {"
974 namespace Foo {
975 struct A {}
976 function B(a : A) : Unit {}
977 }
978 "},
979 &expect![[r#"
980 namespace namespace3 {
981 struct item1 {}
982 function item2(local11 : item1) : Unit {}
983 }
984 "#]],
985 );
986}
987
988#[test]
989fn ty_decl_duplicate_error() {
990 check(
991 indoc! {"
992 namespace Foo {
993 newtype A = Unit;
994 newtype A = Bool;
995 }
996 "},
997 &expect![[r#"
998 namespace namespace3 {
999 newtype item1 = Unit;
1000 newtype item2 = Bool;
1001 }
1002
1003 // Duplicate("A", "Foo", Span { lo: 50, hi: 51 })
1004 "#]],
1005 );
1006}
1007
1008#[test]
1009fn struct_decl_duplicate_error() {
1010 check(
1011 indoc! {"
1012 namespace Foo {
1013 struct A {}
1014 struct A { first : Bool }
1015 }
1016 "},
1017 &expect![[r#"
1018 namespace namespace3 {
1019 struct item1 {}
1020 struct item2 { first : Bool }
1021 }
1022
1023 // Duplicate("A", "Foo", Span { lo: 43, hi: 44 })
1024 "#]],
1025 );
1026}
1027
1028#[test]
1029fn ty_decl_duplicate_error_on_built_in_ty() {
1030 check(
1031 indoc! {"
1032 namespace Std.Core {
1033 newtype Pauli = Unit;
1034 }
1035 "},
1036 &expect![[r#"
1037 namespace namespace2 {
1038 newtype item1 = Unit;
1039 }
1040
1041 // Duplicate("Pauli", "Std.Core", Span { lo: 33, hi: 38 })
1042 "#]],
1043 );
1044}
1045
1046#[test]
1047fn struct_decl_duplicate_error_on_built_in_ty() {
1048 check(
1049 indoc! {"
1050 namespace Std.Core {
1051 struct Pauli {}
1052 }
1053 "},
1054 &expect![[r#"
1055 namespace namespace2 {
1056 struct item1 {}
1057 }
1058
1059 // Duplicate("Pauli", "Std.Core", Span { lo: 32, hi: 37 })
1060 "#]],
1061 );
1062}
1063
1064#[test]
1065fn ty_decl_in_ty_decl() {
1066 check(
1067 indoc! {"
1068 namespace Foo {
1069 newtype A = Unit;
1070 newtype B = A;
1071 }
1072 "},
1073 &expect![[r#"
1074 namespace namespace3 {
1075 newtype item1 = Unit;
1076 newtype item2 = item1;
1077 }
1078 "#]],
1079 );
1080}
1081
1082#[test]
1083fn struct_decl_in_struct_decl() {
1084 check(
1085 indoc! {"
1086 namespace Foo {
1087 struct A {}
1088 struct B { a : A }
1089 }
1090 "},
1091 &expect![[r#"
1092 namespace namespace3 {
1093 struct item1 {}
1094 struct item2 { a : item1 }
1095 }
1096 "#]],
1097 );
1098}
1099
1100#[test]
1101fn ty_decl_recursive() {
1102 check(
1103 indoc! {"
1104 namespace Foo {
1105 newtype A = A;
1106 }
1107 "},
1108 &expect![[r#"
1109 namespace namespace3 {
1110 newtype item1 = item1;
1111 }
1112 "#]],
1113 );
1114}
1115
1116#[test]
1117fn struct_decl_recursive() {
1118 check(
1119 indoc! {"
1120 namespace Foo {
1121 struct A { a : A }
1122 }
1123 "},
1124 &expect![[r#"
1125 namespace namespace3 {
1126 struct item1 { a : item1 }
1127 }
1128 "#]],
1129 );
1130}
1131
1132#[test]
1133fn ty_decl_cons() {
1134 check(
1135 indoc! {"
1136 namespace Foo {
1137 newtype A = Unit;
1138
1139 function B() : A {
1140 A()
1141 }
1142 }
1143 "},
1144 &expect![[r#"
1145 namespace namespace3 {
1146 newtype item1 = Unit;
1147
1148 function item2() : item1 {
1149 item1()
1150 }
1151 }
1152 "#]],
1153 );
1154}
1155
1156#[test]
1157fn struct_decl_call_cons() {
1158 check(
1159 indoc! {"
1160 namespace Foo {
1161 struct A {}
1162
1163 function B() : A {
1164 A()
1165 }
1166 }
1167 "},
1168 &expect![[r#"
1169 namespace namespace3 {
1170 struct item1 {}
1171
1172 function item2() : item1 {
1173 item1()
1174 }
1175 }
1176 "#]],
1177 );
1178}
1179
1180#[test]
1181fn struct_decl_cons() {
1182 check(
1183 indoc! {"
1184 namespace Foo {
1185 struct A {}
1186
1187 function B() : A {
1188 new A {}
1189 }
1190 }
1191 "},
1192 &expect![[r#"
1193 namespace namespace3 {
1194 struct item1 {}
1195
1196 function item2() : item1 {
1197 new item1 {}
1198 }
1199 }
1200 "#]],
1201 );
1202}
1203
1204#[test]
1205fn struct_decl_cons_with_fields() {
1206 check(
1207 indoc! {"
1208 namespace Foo {
1209 struct A {}
1210 struct B {}
1211 struct C { a : A, b : B }
1212
1213 function D() : C {
1214 new C { a = new A {}, b = new B {} }
1215 }
1216 }
1217 "},
1218 &expect![[r#"
1219 namespace namespace3 {
1220 struct item1 {}
1221 struct item2 {}
1222 struct item3 { a : item1, b : item2 }
1223
1224 function item4() : item3 {
1225 new item3 { a = new item1 {}, b = new item2 {} }
1226 }
1227 }
1228 "#]],
1229 );
1230}
1231
1232#[test]
1233fn struct_field_accessor() {
1234 check(
1235 indoc! {"
1236 namespace Foo {
1237 struct A { b : B }
1238 struct B { c : C}
1239 struct C { i : Int }
1240
1241 function D() : Unit {
1242 let a = new A { b = new B { c = new C { i = 4 } } };
1243 let i = a.b.c.i;
1244 }
1245 }
1246 "},
1247 &expect![[r#"
1248 namespace namespace3 {
1249 struct item1 { b : item2 }
1250 struct item2 { c : item3}
1251 struct item3 { i : Int }
1252
1253 function item4() : Unit {
1254 let local37 = new item1 { b = new item2 { c = new item3 { i = 4 } } };
1255 let local56 = local37.b.c.i;
1256 }
1257 }
1258 "#]],
1259 );
1260}
1261
1262#[test]
1263fn struct_field_accessor_with_expr() {
1264 check(
1265 indoc! {"
1266 namespace Foo {
1267 struct A { b : B }
1268 struct B { c : C}
1269 struct C { i : Int }
1270
1271 function D() : Unit {
1272 let a = new A { b = new B { c = new C { i = 4 } } };
1273 let i = { a }.b.c.i;
1274 }
1275 }
1276 "},
1277 &expect![[r#"
1278 namespace namespace3 {
1279 struct item1 { b : item2 }
1280 struct item2 { c : item3}
1281 struct item3 { i : Int }
1282
1283 function item4() : Unit {
1284 let local37 = new item1 { b = new item2 { c = new item3 { i = 4 } } };
1285 let local56 = { local37 }.b.c.i;
1286 }
1287 }
1288 "#]],
1289 );
1290}
1291
1292#[test]
1293fn unknown_term() {
1294 check(
1295 indoc! {"
1296 namespace Foo {
1297 function A() : Unit {
1298 B();
1299 }
1300 }
1301 "},
1302 &expect![[r#"
1303 namespace namespace3 {
1304 function item1() : Unit {
1305 B();
1306 }
1307 }
1308
1309 // NotFound("B", Span { lo: 50, hi: 51 })
1310 "#]],
1311 );
1312}
1313
1314#[test]
1315fn unknown_ty() {
1316 check(
1317 indoc! {"
1318 namespace Foo {
1319 function A(b : B) : Unit {}
1320 }
1321 "},
1322 &expect![[r#"
1323 namespace namespace3 {
1324 function item1(local8 : B) : Unit {}
1325 }
1326
1327 // NotFound("B", Span { lo: 35, hi: 36 })
1328 "#]],
1329 );
1330}
1331
1332#[test]
1333fn open_ambiguous_terms() {
1334 check(
1335 indoc! {"
1336 namespace Foo {
1337 function A() : Unit {}
1338 }
1339
1340 namespace Bar {
1341 function A() : Unit {}
1342 }
1343
1344 namespace Baz {
1345 open Foo;
1346 open Bar;
1347
1348 function C() : Unit {
1349 A();
1350 }
1351 }
1352 "},
1353 &expect![[r#"
1354 namespace namespace3 {
1355 function item1() : Unit {}
1356 }
1357
1358 namespace namespace4 {
1359 function item3() : Unit {}
1360 }
1361
1362 namespace namespace5 {
1363 open namespace3;
1364 open namespace4;
1365
1366 function item5() : Unit {
1367 A();
1368 }
1369 }
1370
1371 // Ambiguous { name: "A", first_open: "Foo", second_open: "Bar", name_span: Span { lo: 171, hi: 172 }, first_open_span: Span { lo: 117, hi: 120 }, second_open_span: Span { lo: 131, hi: 134 } }
1372 "#]],
1373 );
1374}
1375
1376#[test]
1377fn open_ambiguous_tys() {
1378 check(
1379 indoc! {"
1380 namespace Foo {
1381 newtype A = Unit;
1382 }
1383
1384 namespace Bar {
1385 newtype A = Unit;
1386 }
1387
1388 namespace Baz {
1389 open Foo;
1390 open Bar;
1391
1392 function C(a : A) : Unit {}
1393 }
1394 "},
1395 &expect![[r#"
1396 namespace namespace3 {
1397 newtype item1 = Unit;
1398 }
1399
1400 namespace namespace4 {
1401 newtype item3 = Unit;
1402 }
1403
1404 namespace namespace5 {
1405 open namespace3;
1406 open namespace4;
1407
1408 function item5(local30 : A) : Unit {}
1409 }
1410
1411 // Ambiguous { name: "A", first_open: "Foo", second_open: "Bar", name_span: Span { lo: 146, hi: 147 }, first_open_span: Span { lo: 107, hi: 110 }, second_open_span: Span { lo: 121, hi: 124 } }
1412 "#]],
1413 );
1414}
1415
1416#[test]
1417fn merged_aliases_ambiguous_terms() {
1418 check(
1419 indoc! {"
1420 namespace Foo {
1421 function A() : Unit {}
1422 }
1423
1424 namespace Bar {
1425 function A() : Unit {}
1426 }
1427
1428 namespace Baz {
1429 open Foo as Alias;
1430 open Bar as Alias;
1431
1432 function C() : Unit {
1433 Alias.A();
1434 }
1435 }
1436 "},
1437 &expect![[r#"
1438 namespace namespace3 {
1439 function item1() : Unit {}
1440 }
1441
1442 namespace namespace4 {
1443 function item3() : Unit {}
1444 }
1445
1446 namespace namespace5 {
1447 open namespace3 as Alias;
1448 open namespace4 as Alias;
1449
1450 function item5() : Unit {
1451 namespace4.A();
1452 }
1453 }
1454
1455 // Ambiguous { name: "A", first_open: "Foo", second_open: "Bar", name_span: Span { lo: 195, hi: 196 }, first_open_span: Span { lo: 117, hi: 120 }, second_open_span: Span { lo: 140, hi: 143 } }
1456 "#]],
1457 );
1458}
1459
1460#[test]
1461fn merged_aliases_ambiguous_tys() {
1462 check(
1463 indoc! {"
1464 namespace Foo {
1465 newtype A = Unit;
1466 }
1467
1468 namespace Bar {
1469 newtype A = Unit;
1470 }
1471
1472 namespace Baz {
1473 open Foo as Alias;
1474 open Bar as Alias;
1475
1476 function C(a : Alias.A) : Unit {}
1477 }
1478 "},
1479 &expect![[r#"
1480 namespace namespace3 {
1481 newtype item1 = Unit;
1482 }
1483
1484 namespace namespace4 {
1485 newtype item3 = Unit;
1486 }
1487
1488 namespace namespace5 {
1489 open namespace3 as Alias;
1490 open namespace4 as Alias;
1491
1492 function item5(local32 : namespace4.A) : Unit {}
1493 }
1494
1495 // Ambiguous { name: "A", first_open: "Foo", second_open: "Bar", name_span: Span { lo: 170, hi: 171 }, first_open_span: Span { lo: 107, hi: 110 }, second_open_span: Span { lo: 130, hi: 133 } }
1496 "#]],
1497 );
1498}
1499
1500#[test]
1501fn lambda_param() {
1502 check(
1503 indoc! {"
1504 namespace Foo {
1505 function A() : Unit {
1506 let f = x -> x + 1;
1507 }
1508 }
1509 "},
1510 &expect![[r#"
1511 namespace namespace3 {
1512 function item1() : Unit {
1513 let local13 = local16 -> local16 + 1;
1514 }
1515 }
1516 "#]],
1517 );
1518}
1519
1520#[test]
1521fn lambda_shadows_local() {
1522 check(
1523 indoc! {"
1524 namespace Foo {
1525 function A() : Int {
1526 let x = 1;
1527 let f = x -> x + 1;
1528 x
1529 }
1530 }
1531 "},
1532 &expect![[r#"
1533 namespace namespace3 {
1534 function item1() : Int {
1535 let local13 = 1;
1536 let local17 = local20 -> local20 + 1;
1537 local13
1538 }
1539 }
1540 "#]],
1541 );
1542}
1543
1544#[test]
1545fn for_loop_range() {
1546 check(
1547 indoc! {"
1548 namespace Foo {
1549 function A() : Unit {
1550 for i in 0..9 {
1551 let _ = i;
1552 }
1553 }
1554 }
1555 "},
1556 &expect![[r#"
1557 namespace namespace3 {
1558 function item1() : Unit {
1559 for local14 in 0..9 {
1560 let _ = local14;
1561 }
1562 }
1563 }
1564 "#]],
1565 );
1566}
1567
1568#[test]
1569fn for_loop_var() {
1570 check(
1571 indoc! {"
1572 namespace Foo {
1573 function A(xs : Int[]) : Unit {
1574 for x in xs {
1575 let _ = x;
1576 }
1577 }
1578 }
1579 "},
1580 &expect![[r#"
1581 namespace namespace3 {
1582 function item1(local8 : Int[]) : Unit {
1583 for local20 in local8 {
1584 let _ = local20;
1585 }
1586 }
1587 }
1588 "#]],
1589 );
1590}
1591
1592#[test]
1593fn for_loop_explicit_type() {
1594 check(
1595 indoc! {"
1596 namespace Foo {
1597 function A() : Unit {
1598 for i : Int in 0..9 {
1599 let _ = i;
1600 }
1601 }
1602 }
1603 "},
1604 &expect![[r#"
1605 namespace namespace3 {
1606 function item1() : Unit {
1607 for local14 : Int in 0..9 {
1608 let _ = local14;
1609 }
1610 }
1611 }
1612 "#]],
1613 );
1614}
1615
1616#[test]
1617fn repeat_until() {
1618 check(
1619 indoc! {"
1620 namespace Foo {
1621 operation A() : Unit {
1622 mutable cond = false;
1623 repeat {
1624 set cond = true;
1625 } until cond;
1626 }
1627 }
1628 "},
1629 &expect![[r#"
1630 namespace namespace3 {
1631 operation item1() : Unit {
1632 mutable local13 = false;
1633 repeat {
1634 set local13 = true;
1635 } until local13;
1636 }
1637 }
1638 "#]],
1639 );
1640}
1641
1642#[test]
1643fn repeat_until_fixup() {
1644 check(
1645 indoc! {"
1646 namespace Foo {
1647 operation A() : Unit {
1648 mutable cond = false;
1649 repeat {
1650 set cond = false;
1651 } until cond
1652 fixup {
1653 set cond = true;
1654 }
1655 }
1656 }
1657 "},
1658 &expect![[r#"
1659 namespace namespace3 {
1660 operation item1() : Unit {
1661 mutable local13 = false;
1662 repeat {
1663 set local13 = false;
1664 } until local13
1665 fixup {
1666 set local13 = true;
1667 }
1668 }
1669 }
1670 "#]],
1671 );
1672}
1673
1674#[test]
1675fn repeat_until_fixup_scoping() {
1676 check(
1677 indoc! {"
1678 namespace Foo {
1679 operation A() : Unit {
1680 repeat {
1681 mutable cond = false;
1682 }
1683 until cond
1684 fixup {
1685 set cond = true;
1686 }
1687 }
1688 }"},
1689 &expect![[r#"
1690 namespace namespace3 {
1691 operation item1() : Unit {
1692 repeat {
1693 mutable local16 = false;
1694 }
1695 until cond
1696 fixup {
1697 set cond = true;
1698 }
1699 }
1700 }
1701 // NotFound("cond", Span { lo: 118, hi: 122 })
1702 // NotFound("cond", Span { lo: 155, hi: 159 })
1703 "#]],
1704 );
1705}
1706
1707#[test]
1708fn use_qubit() {
1709 check(
1710 indoc! {"
1711 namespace Foo {
1712 operation X(q : Qubit) : Unit {
1713 body intrinsic;
1714 }
1715 operation A() : Unit {
1716 use q = Qubit();
1717 X(q);
1718 }
1719 }
1720 "},
1721 &expect![[r#"
1722 namespace namespace3 {
1723 operation item1(local8 : Qubit) : Unit {
1724 body intrinsic;
1725 }
1726 operation item2() : Unit {
1727 use local26 = Qubit();
1728 item1(local26);
1729 }
1730 }
1731 "#]],
1732 );
1733}
1734
1735#[test]
1736fn use_qubit_block() {
1737 check(
1738 indoc! {"
1739 namespace Foo {
1740 operation X(q : Qubit) : Unit {
1741 body intrinsic;
1742 }
1743 operation A() : Unit {
1744 use q = Qubit() {
1745 X(q);
1746 }
1747 }
1748 }
1749 "},
1750 &expect![[r#"
1751 namespace namespace3 {
1752 operation item1(local8 : Qubit) : Unit {
1753 body intrinsic;
1754 }
1755 operation item2() : Unit {
1756 use local26 = Qubit() {
1757 item1(local26);
1758 }
1759 }
1760 }
1761 "#]],
1762 );
1763}
1764
1765#[test]
1766fn use_qubit_block_qubit_restricted_to_block_scope() {
1767 check(
1768 indoc! {"
1769 namespace Foo {
1770 operation X(q : Qubit) : Unit {
1771 body intrinsic;
1772 }
1773 operation A() : Unit {
1774 use q = Qubit() {
1775 X(q);
1776 }
1777 X(q);
1778 }
1779 }
1780 "},
1781 &expect![[r#"
1782 namespace namespace3 {
1783 operation item1(local8 : Qubit) : Unit {
1784 body intrinsic;
1785 }
1786 operation item2() : Unit {
1787 use local26 = Qubit() {
1788 item1(local26);
1789 }
1790 item1(q);
1791 }
1792 }
1793
1794 // NotFound("q", Span { lo: 173, hi: 174 })
1795 "#]],
1796 );
1797}
1798
1799#[test]
1800fn local_function() {
1801 check(
1802 indoc! {"
1803 namespace A {
1804 function Foo() : Int {
1805 function Bar() : Int { 2 }
1806 Bar() + 1
1807 }
1808 }
1809 "},
1810 &expect![[r#"
1811 namespace namespace3 {
1812 function item1() : Int {
1813 function item2() : Int { 2 }
1814 item2() + 1
1815 }
1816 }
1817 "#]],
1818 );
1819}
1820
1821#[test]
1822fn local_function_use_before_declare() {
1823 check(
1824 indoc! {"
1825 namespace A {
1826 function Foo() : () {
1827 Bar();
1828 function Bar() : () {}
1829 }
1830 }
1831 "},
1832 &expect![[r#"
1833 namespace namespace3 {
1834 function item1() : () {
1835 item2();
1836 function item2() : () {}
1837 }
1838 }
1839 "#]],
1840 );
1841}
1842
1843#[test]
1844fn local_function_is_really_local() {
1845 check(
1846 indoc! {"
1847 namespace A {
1848 function Foo() : () {
1849 function Bar() : () {}
1850 Bar();
1851 }
1852
1853 function Baz() : () { Bar(); }
1854 }
1855 "},
1856 &expect![[r#"
1857 namespace namespace3 {
1858 function item1() : () {
1859 function item3() : () {}
1860 item3();
1861 }
1862
1863 function item2() : () { Bar(); }
1864 }
1865
1866 // NotFound("Bar", Span { lo: 119, hi: 122 })
1867 "#]],
1868 );
1869}
1870
1871#[test]
1872fn local_function_is_not_closure() {
1873 check(
1874 indoc! {"
1875 namespace A {
1876 function Foo() : () {
1877 let x = 2;
1878 function Bar() : Int { x }
1879 }
1880 }
1881 "},
1882 &expect![[r#"
1883 namespace namespace3 {
1884 function item1() : () {
1885 let local11 = 2;
1886 function item2() : Int { x }
1887 }
1888 }
1889
1890 // NotFound("x", Span { lo: 90, hi: 91 })
1891 "#]],
1892 );
1893}
1894
1895#[test]
1896fn local_type() {
1897 check(
1898 indoc! {"
1899 namespace A {
1900 function Foo() : () {
1901 newtype Bar = Int;
1902 let x = Bar(5);
1903 }
1904 }
1905 "},
1906 &expect![[r#"
1907 namespace namespace3 {
1908 function item1() : () {
1909 newtype item2 = Int;
1910 let local18 = item2(5);
1911 }
1912 }
1913 "#]],
1914 );
1915}
1916
1917#[test]
1918fn local_open() {
1919 check(
1920 indoc! {"
1921 namespace A { function Foo() : () { open B; Bar(); } }
1922 namespace B { function Bar() : () {} }
1923 "},
1924 &expect![[r#"
1925 namespace namespace3 { function item1() : () { open namespace4; item3(); } }
1926 namespace namespace4 { function item3() : () {} }
1927 "#]],
1928 );
1929}
1930
1931#[test]
1932fn local_open_shadows_parent_item() {
1933 check(
1934 indoc! {"
1935 namespace A {
1936 function Bar() : () {}
1937 function Foo() : () { open B; Bar(); }
1938 }
1939
1940 namespace B { function Bar() : () {} }
1941 "},
1942 &expect![[r#"
1943 namespace namespace3 {
1944 function item1() : () {}
1945 function item2() : () { open namespace4; item4(); }
1946 }
1947
1948 namespace namespace4 { function item4() : () {} }
1949 "#]],
1950 );
1951}
1952
1953#[test]
1954fn local_open_shadows_parent_open() {
1955 check(
1956 indoc! {"
1957 namespace A {
1958 open B;
1959 function Foo() : () { open C; Bar(); }
1960 }
1961
1962 namespace B { function Bar() : () {} }
1963 namespace C { function Bar() : () {} }
1964 "},
1965 &expect![[r#"
1966 namespace namespace3 {
1967 open namespace4;
1968 function item1() : () { open namespace5; item5(); }
1969 }
1970
1971 namespace namespace4 { function item3() : () {} }
1972 namespace namespace5 { function item5() : () {} }
1973 "#]],
1974 );
1975}
1976
1977#[test]
1978fn update_array_index_var() {
1979 check(
1980 indoc! {"
1981 namespace A {
1982 function Foo() : () {
1983 let xs = [2];
1984 let i = 0;
1985 let ys = xs w/ i <- 3;
1986 }
1987 }
1988 "},
1989 &expect![[r#"
1990 namespace namespace3 {
1991 function item1() : () {
1992 let local11 = [2];
1993 let local16 = 0;
1994 let local20 = local11 w/ local16 <- 3;
1995 }
1996 }
1997 "#]],
1998 );
1999}
2000
2001#[test]
2002fn update_array_index_expr() {
2003 check(
2004 indoc! {"
2005 namespace A {
2006 function Foo() : () {
2007 let xs = [2];
2008 let i = 0;
2009 let ys = xs w/ i + 1 <- 3;
2010 }
2011 }
2012 "},
2013 &expect![[r#"
2014 namespace namespace3 {
2015 function item1() : () {
2016 let local11 = [2];
2017 let local16 = 0;
2018 let local20 = local11 w/ local16 + 1 <- 3;
2019 }
2020 }
2021 "#]],
2022 );
2023}
2024
2025#[test]
2026fn update_udt_known_field_name() {
2027 check(
2028 indoc! {"
2029 namespace A {
2030 newtype Pair = (First : Int, Second : Int);
2031
2032 function Foo() : () {
2033 let p = Pair(1, 2);
2034 let q = p w/ First <- 3;
2035 }
2036 }
2037 "},
2038 &expect![[r#"
2039 namespace namespace3 {
2040 newtype item1 = (First : Int, Second : Int);
2041
2042 function item2() : () {
2043 let local24 = item1(1, 2);
2044 let local34 = local24 w/ First <- 3;
2045 }
2046 }
2047 "#]],
2048 );
2049}
2050
2051#[test]
2052fn update_udt_known_field_name_expr() {
2053 check(
2054 indoc! {"
2055 namespace A {
2056 newtype Pair = (First : Int, Second : Int);
2057
2058 function Foo() : () {
2059 let p = Pair(1, 2);
2060 let q = p w/ First + 1 <- 3;
2061 }
2062 }
2063 "},
2064 &expect![[r#"
2065 namespace namespace3 {
2066 newtype item1 = (First : Int, Second : Int);
2067
2068 function item2() : () {
2069 let local24 = item1(1, 2);
2070 let local34 = local24 w/ First + 1 <- 3;
2071 }
2072 }
2073
2074 // NotFound("First", Span { lo: 138, hi: 143 })
2075 "#]],
2076 );
2077}
2078
2079#[test]
2080fn update_udt_unknown_field_name() {
2081 check(
2082 indoc! {"
2083 namespace A {
2084 newtype Pair = (First : Int, Second : Int);
2085
2086 function Foo() : () {
2087 let p = Pair(1, 2);
2088 let q = p w/ Third <- 3;
2089 }
2090 }
2091 "},
2092 &expect![[r#"
2093 namespace namespace3 {
2094 newtype item1 = (First : Int, Second : Int);
2095
2096 function item2() : () {
2097 let local24 = item1(1, 2);
2098 let local34 = local24 w/ Third <- 3;
2099 }
2100 }
2101 "#]],
2102 );
2103}
2104
2105#[test]
2106fn update_udt_unknown_field_name_known_global() {
2107 check(
2108 indoc! {"
2109 namespace A {
2110 newtype Pair = (First : Int, Second : Int);
2111
2112 function Third() : () {}
2113
2114 function Foo() : () {
2115 let p = Pair(1, 2);
2116 let q = p w/ Third <- 3;
2117 }
2118 }
2119 "},
2120 &expect![[r#"
2121 namespace namespace3 {
2122 newtype item1 = (First : Int, Second : Int);
2123
2124 function item2() : () {}
2125
2126 function item3() : () {
2127 let local30 = item1(1, 2);
2128 let local40 = local30 w/ Third <- 3;
2129 }
2130 }
2131 "#]],
2132 );
2133}
2134
2135#[test]
2136fn unknown_namespace() {
2137 check(
2138 indoc! {"
2139 namespace A {
2140 import Std.Fake.*;
2141 }
2142 "},
2143 &expect![[r#"
2144 namespace namespace3 {
2145 import Std.Fake.*;
2146 }
2147
2148 // GlobImportNamespaceNotFound("Fake", Span { lo: 25, hi: 33 })
2149 "#]],
2150 );
2151}
2152
2153#[test]
2154fn empty_namespace_works() {
2155 check(
2156 indoc! {"
2157 namespace A {
2158 open B;
2159 function foo(): Unit{}
2160 }
2161 namespace B {}
2162 "},
2163 &expect![[r#"
2164 namespace namespace3 {
2165 open namespace4;
2166 function item1(): Unit{}
2167 }
2168 namespace namespace4 {}
2169 "#]],
2170 );
2171}
2172
2173#[test]
2174fn cyclic_namespace_dependency_supported() {
2175 check(
2176 indoc! {"
2177 namespace A {
2178 open B;
2179 operation Foo() : Unit {
2180 Bar();
2181 }
2182 }
2183 namespace B {
2184 open A;
2185 operation Bar() : Unit {
2186 Foo();
2187 }
2188 }
2189 "},
2190 &expect![[r#"
2191 namespace namespace3 {
2192 open namespace4;
2193 operation item1() : Unit {
2194 item3();
2195 }
2196 }
2197 namespace namespace4 {
2198 open namespace3;
2199 operation item3() : Unit {
2200 item1();
2201 }
2202 }
2203 "#]],
2204 );
2205}
2206
2207#[test]
2208fn bind_items_in_repeat() {
2209 check(
2210 indoc! {"
2211 namespace A {
2212 operation B() : Unit {
2213 repeat {
2214 function C() : Unit {}
2215 } until false
2216 fixup {
2217 function D() : Unit {}
2218 }
2219 }
2220 }
2221 "},
2222 &expect![[r#"
2223 namespace namespace3 {
2224 operation item1() : Unit {
2225 repeat {
2226 function item2() : Unit {}
2227 } until false
2228 fixup {
2229 function item3() : Unit {}
2230 }
2231 }
2232 }
2233 "#]],
2234 );
2235}
2236
2237#[test]
2238fn bind_items_in_qubit_use_block() {
2239 check(
2240 indoc! {"
2241 namespace A {
2242 operation B() : Unit {
2243 use q = Qubit() {
2244 function C() : Unit {}
2245 }
2246 }
2247 }
2248 "},
2249 &expect![[r#"
2250 namespace namespace3 {
2251 operation item1() : Unit {
2252 use local13 = Qubit() {
2253 function item2() : Unit {}
2254 }
2255 }
2256 }
2257 "#]],
2258 );
2259}
2260
2261#[test]
2262fn use_bound_item_in_another_bound_item() {
2263 check(
2264 indoc! {"
2265 namespace A {
2266 function B() : Unit {
2267 function C() : Unit {
2268 D();
2269 }
2270 function D() : Unit {}
2271 }
2272 }
2273 "},
2274 &expect![[r#"
2275 namespace namespace3 {
2276 function item1() : Unit {
2277 function item2() : Unit {
2278 item3();
2279 }
2280 function item3() : Unit {}
2281 }
2282 }
2283 "#]],
2284 );
2285}
2286
2287#[test]
2288fn use_unbound_generic() {
2289 check(
2290 indoc! {"
2291 namespace A {
2292 function B<'T>(x: 'U) : 'U {
2293 x
2294 }
2295 }
2296 "},
2297 &expect![[r#"
2298 namespace namespace3 {
2299 function item1<param0>(local9: 'U) : 'U {
2300 local9
2301 }
2302 }
2303
2304 // NotFound("'U", Span { lo: 36, hi: 38 })
2305 // NotFound("'U", Span { lo: 42, hi: 44 })
2306 "#]],
2307 );
2308}
2309
2310#[test]
2311fn resolve_local_generic() {
2312 check(
2313 indoc! {"
2314 namespace A {
2315 function B<'T>(x: 'T) : 'T {
2316 x
2317 }
2318 }
2319 "},
2320 &expect![[r#"
2321 namespace namespace3 {
2322 function item1<param0>(local9: param0) : param0 {
2323 local9
2324 }
2325 }
2326 "#]],
2327 );
2328}
2329
2330#[test]
2331fn dropped_base_callable_from_unrestricted() {
2332 check_with_capabilities(
2333 indoc! {"
2334 namespace A {
2335 @Config(Base)
2336 function Dropped() : Unit {}
2337
2338 function B() : Unit {
2339 Dropped();
2340 }
2341 }
2342 "},
2343 TargetCapabilityFlags::all(),
2344 &expect![[r#"
2345 namespace namespace3 {
2346 @Config(Base)
2347 function Dropped() : Unit {}
2348
2349 function item1() : Unit {
2350 Dropped();
2351 }
2352 }
2353
2354 // NotAvailable("Dropped", "A.Dropped", Span { lo: 100, hi: 107 })
2355 "#]],
2356 );
2357}
2358
2359#[test]
2360fn dropped_base_callable_from_adaptive() {
2361 check_with_capabilities(
2362 indoc! {"
2363 namespace A {
2364 @Config(Base)
2365 function Dropped() : Unit {}
2366
2367 function B() : Unit {
2368 Dropped();
2369 }
2370 }
2371 "},
2372 TargetCapabilityFlags::Adaptive,
2373 &expect![[r#"
2374 namespace namespace3 {
2375 @Config(Base)
2376 function Dropped() : Unit {}
2377
2378 function item1() : Unit {
2379 Dropped();
2380 }
2381 }
2382
2383 // NotAvailable("Dropped", "A.Dropped", Span { lo: 100, hi: 107 })
2384 "#]],
2385 );
2386}
2387
2388#[test]
2389fn dropped_not_base_callable_from_base() {
2390 check_with_capabilities(
2391 indoc! {"
2392 namespace A {
2393 @Config(not Base)
2394 function Dropped() : Unit {}
2395
2396 function B() : Unit {
2397 Dropped();
2398 }
2399 }
2400 "},
2401 TargetCapabilityFlags::empty(),
2402 &expect![[r#"
2403 namespace namespace3 {
2404 @Config(not Base)
2405 function Dropped() : Unit {}
2406
2407 function item1() : Unit {
2408 Dropped();
2409 }
2410 }
2411
2412 // NotAvailable("Dropped", "A.Dropped", Span { lo: 104, hi: 111 })
2413 "#]],
2414 );
2415}
2416
2417#[test]
2418fn resolved_not_base_callable_from_adaptive() {
2419 check_with_capabilities(
2420 indoc! {"
2421 namespace A {
2422 @Config(not Base)
2423 function Dropped() : Unit {}
2424
2425 function B() : Unit {
2426 Dropped();
2427 }
2428 }
2429 "},
2430 TargetCapabilityFlags::Adaptive,
2431 &expect![[r#"
2432 namespace namespace3 {
2433 @Config(not Base)
2434 function item1() : Unit {}
2435
2436 function item2() : Unit {
2437 item1();
2438 }
2439 }
2440 "#]],
2441 );
2442}
2443
2444#[test]
2445fn dropped_base_and_not_base_callable_from_base() {
2446 check_with_capabilities(
2447 indoc! {"
2448 namespace A {
2449 @Config(Base)
2450 @Config(not Base)
2451 function Dropped() : Unit {}
2452
2453 function B() : Unit {
2454 Dropped();
2455 }
2456 }
2457 "},
2458 TargetCapabilityFlags::empty(),
2459 &expect![[r#"
2460 namespace namespace3 {
2461 @Config(Base)
2462 @Config(not Base)
2463 function Dropped() : Unit {}
2464
2465 function item1() : Unit {
2466 Dropped();
2467 }
2468 }
2469
2470 // NotAvailable("Dropped", "A.Dropped", Span { lo: 122, hi: 129 })
2471 "#]],
2472 );
2473}
2474
2475#[test]
2476fn resolved_not_unrestricted_callable_from_base() {
2477 check_with_capabilities(
2478 indoc! {"
2479 namespace A {
2480 @Config(not Unrestricted)
2481 function Dropped() : Unit {}
2482
2483 function B() : Unit {
2484 Dropped();
2485 }
2486 }
2487 "},
2488 TargetCapabilityFlags::empty(),
2489 &expect![[r#"
2490 namespace namespace3 {
2491 @Config(not Unrestricted)
2492 function item1() : Unit {}
2493
2494 function item2() : Unit {
2495 item1();
2496 }
2497 }
2498 "#]],
2499 );
2500}
2501
2502#[test]
2503fn resolved_not_unrestricted_callable_from_adaptive() {
2504 check_with_capabilities(
2505 indoc! {"
2506 namespace A {
2507 @Config(not Unrestricted)
2508 function Dropped() : Unit {}
2509
2510 function B() : Unit {
2511 Dropped();
2512 }
2513 }
2514 "},
2515 TargetCapabilityFlags::Adaptive,
2516 &expect![[r#"
2517 namespace namespace3 {
2518 @Config(not Unrestricted)
2519 function item1() : Unit {}
2520
2521 function item2() : Unit {
2522 item1();
2523 }
2524 }
2525 "#]],
2526 );
2527}
2528
2529#[test]
2530fn dropped_not_unrestricted_callable_from_unrestricted() {
2531 check_with_capabilities(
2532 indoc! {"
2533 namespace A {
2534 @Config(not Unrestricted)
2535 function Dropped() : Unit {}
2536
2537 function B() : Unit {
2538 Dropped();
2539 }
2540 }
2541 "},
2542 TargetCapabilityFlags::all(),
2543 &expect![[r#"
2544 namespace namespace3 {
2545 @Config(not Unrestricted)
2546 function Dropped() : Unit {}
2547
2548 function item1() : Unit {
2549 Dropped();
2550 }
2551 }
2552
2553 // NotAvailable("Dropped", "A.Dropped", Span { lo: 112, hi: 119 })
2554 "#]],
2555 );
2556}
2557
2558#[test]
2559fn resolved_adaptive_callable_from_adaptive() {
2560 check_with_capabilities(
2561 indoc! {"
2562 namespace A {
2563 @Config(Adaptive)
2564 function Dropped() : Unit {}
2565
2566 function B() : Unit {
2567 Dropped();
2568 }
2569 }
2570 "},
2571 TargetCapabilityFlags::Adaptive,
2572 &expect![[r#"
2573 namespace namespace3 {
2574 @Config(Adaptive)
2575 function item1() : Unit {}
2576
2577 function item2() : Unit {
2578 item1();
2579 }
2580 }
2581 "#]],
2582 );
2583}
2584
2585#[test]
2586fn resolved_adaptive_callable_from_unrestricted() {
2587 check_with_capabilities(
2588 indoc! {"
2589 namespace A {
2590 @Config(Adaptive)
2591 function Dropped() : Unit {}
2592
2593 function B() : Unit {
2594 Dropped();
2595 }
2596 }
2597 "},
2598 TargetCapabilityFlags::all(),
2599 &expect![[r#"
2600 namespace namespace3 {
2601 @Config(Adaptive)
2602 function item1() : Unit {}
2603
2604 function item2() : Unit {
2605 item1();
2606 }
2607 }
2608 "#]],
2609 );
2610}
2611
2612#[test]
2613fn dropped_not_higher_level_callable_from_unrestricted() {
2614 check_with_capabilities(
2615 indoc! {"
2616 namespace A {
2617 @Config(not HigherLevelConstructs)
2618 function Dropped() : Unit {}
2619
2620 function B() : Unit {
2621 Dropped();
2622 }
2623 }
2624 "},
2625 TargetCapabilityFlags::all(),
2626 &expect![[r#"
2627 namespace namespace3 {
2628 @Config(not HigherLevelConstructs)
2629 function Dropped() : Unit {}
2630
2631 function item1() : Unit {
2632 Dropped();
2633 }
2634 }
2635
2636 // NotAvailable("Dropped", "A.Dropped", Span { lo: 121, hi: 128 })
2637 "#]],
2638 );
2639}
2640
2641#[test]
2642fn resolved_not_higher_level_callable_from_adaptive() {
2643 check_with_capabilities(
2644 indoc! {"
2645 namespace A {
2646 @Config(not HigherLevelConstructs)
2647 function Dropped() : Unit {}
2648
2649 function B() : Unit {
2650 Dropped();
2651 }
2652 }
2653 "},
2654 TargetCapabilityFlags::Adaptive,
2655 &expect![[r#"
2656 namespace namespace3 {
2657 @Config(not HigherLevelConstructs)
2658 function item1() : Unit {}
2659
2660 function item2() : Unit {
2661 item1();
2662 }
2663 }
2664 "#]],
2665 );
2666}
2667
2668#[test]
2669fn resolved_not_higher_level_callable_from_base() {
2670 check_with_capabilities(
2671 indoc! {"
2672 namespace A {
2673 @Config(not HigherLevelConstructs)
2674 function Dropped() : Unit {}
2675
2676 function B() : Unit {
2677 Dropped();
2678 }
2679 }
2680 "},
2681 TargetCapabilityFlags::empty(),
2682 &expect![[r#"
2683 namespace namespace3 {
2684 @Config(not HigherLevelConstructs)
2685 function item1() : Unit {}
2686
2687 function item2() : Unit {
2688 item1();
2689 }
2690 }
2691 "#]],
2692 );
2693}
2694
2695#[test]
2696fn dropped_not_higher_level_and_adaptive_callable_from_base() {
2697 check_with_capabilities(
2698 indoc! {"
2699 namespace A {
2700 @Config(Adaptive)
2701 @Config(not HigherLevelConstructs)
2702 function Dropped() : Unit {}
2703
2704 function B() : Unit {
2705 Dropped();
2706 }
2707 }
2708 "},
2709 TargetCapabilityFlags::empty(),
2710 &expect![[r#"
2711 namespace namespace3 {
2712 @Config(Adaptive)
2713 @Config(not HigherLevelConstructs)
2714 function Dropped() : Unit {}
2715
2716 function item1() : Unit {
2717 Dropped();
2718 }
2719 }
2720
2721 // NotAvailable("Dropped", "A.Dropped", Span { lo: 143, hi: 150 })
2722 "#]],
2723 );
2724}
2725
2726#[test]
2727fn dropped_not_higher_level_and_adaptive_callable_from_unrestricted() {
2728 check_with_capabilities(
2729 indoc! {"
2730 namespace A {
2731 @Config(Adaptive)
2732 @Config(not HigherLevelConstructs)
2733 function Dropped() : Unit {}
2734
2735 function B() : Unit {
2736 Dropped();
2737 }
2738 }
2739 "},
2740 TargetCapabilityFlags::all(),
2741 &expect![[r#"
2742 namespace namespace3 {
2743 @Config(Adaptive)
2744 @Config(not HigherLevelConstructs)
2745 function Dropped() : Unit {}
2746
2747 function item1() : Unit {
2748 Dropped();
2749 }
2750 }
2751
2752 // NotAvailable("Dropped", "A.Dropped", Span { lo: 143, hi: 150 })
2753 "#]],
2754 );
2755}
2756
2757#[test]
2758fn resolved_not_higher_level_and_adaptive_callable_from_adaptive() {
2759 check_with_capabilities(
2760 indoc! {"
2761 namespace A {
2762 @Config(Adaptive)
2763 @Config(not HigherLevelConstructs)
2764 function Dropped() : Unit {}
2765
2766 function B() : Unit {
2767 Dropped();
2768 }
2769 }
2770 "},
2771 TargetCapabilityFlags::Adaptive,
2772 &expect![[r#"
2773 namespace namespace3 {
2774 @Config(Adaptive)
2775 @Config(not HigherLevelConstructs)
2776 function item1() : Unit {}
2777
2778 function item2() : Unit {
2779 item1();
2780 }
2781 }
2782 "#]],
2783 );
2784}
2785
2786#[test]
2787fn dropped_floating_point_from_adaptive() {
2788 check_with_capabilities(
2789 indoc! {"
2790 namespace A {
2791 @Config(FloatingPointComputations)
2792 function Dropped() : Double {}
2793
2794 function B() : Unit {
2795 Dropped();
2796 }
2797 }
2798 "},
2799 TargetCapabilityFlags::Adaptive,
2800 &expect![[r#"
2801 namespace namespace3 {
2802 @Config(FloatingPointComputations)
2803 function Dropped() : Double {}
2804
2805 function item1() : Unit {
2806 Dropped();
2807 }
2808 }
2809
2810 // NotAvailable("Dropped", "A.Dropped", Span { lo: 123, hi: 130 })
2811 "#]],
2812 );
2813}
2814
2815#[test]
2816fn resolved_adaptive_and_integer_from_adaptive_and_integer() {
2817 check_with_capabilities(
2818 indoc! {"
2819 namespace A {
2820 @Config(Adaptive)
2821 @Config(IntegerComputations)
2822 function Dropped() : Double {}
2823
2824 function B() : Unit {
2825 Dropped();
2826 }
2827 }
2828 "},
2829 TargetCapabilityFlags::Adaptive | TargetCapabilityFlags::IntegerComputations,
2830 &expect![[r#"
2831 namespace namespace3 {
2832 @Config(Adaptive)
2833 @Config(IntegerComputations)
2834 function item1() : Double {}
2835
2836 function item2() : Unit {
2837 item1();
2838 }
2839 }
2840 "#]],
2841 );
2842}
2843
2844#[test]
2845fn multiple_definition_dropped_is_not_found() {
2846 check(
2847 indoc! {"
2848 namespace A {
2849 @Config(Adaptive)
2850 operation B() : Unit {}
2851 @Config(Base)
2852 operation B() : Unit {}
2853 @Config(Base)
2854 operation C() : Unit {}
2855 @Config(Adaptive)
2856 operation C() : Unit {}
2857 }
2858 namespace D {
2859 operation E() : Unit {
2860 B();
2861 C();
2862 }
2863 operation F() : Unit {
2864 open A;
2865 B();
2866 C();
2867 }
2868 }
2869 "},
2870 &expect![[r#"
2871 namespace namespace3 {
2872 @Config(Adaptive)
2873 operation item1() : Unit {}
2874 @Config(Base)
2875 operation B() : Unit {}
2876 @Config(Base)
2877 operation C() : Unit {}
2878 @Config(Adaptive)
2879 operation item2() : Unit {}
2880 }
2881 namespace namespace4 {
2882 operation item4() : Unit {
2883 B();
2884 C();
2885 }
2886 operation item5() : Unit {
2887 open namespace3;
2888 item1();
2889 item2();
2890 }
2891 }
2892
2893 // NotFound("B", Span { lo: 257, hi: 258 })
2894 // NotFound("C", Span { lo: 270, hi: 271 })
2895 "#]],
2896 );
2897}
2898
2899#[test]
2900fn disallow_duplicate_intrinsic() {
2901 check(
2902 indoc! {"
2903 namespace A {
2904 operation B() : Unit {
2905 body intrinsic;
2906 }
2907 }
2908 namespace B {
2909 operation B() : Unit {
2910 body intrinsic;
2911 }
2912 }
2913 "},
2914 &expect![[r#"
2915 namespace namespace3 {
2916 operation item1() : Unit {
2917 body intrinsic;
2918 }
2919 }
2920 namespace namespace4 {
2921 operation item3() : Unit {
2922 body intrinsic;
2923 }
2924 }
2925
2926 // DuplicateIntrinsic("B", Span { lo: 101, hi: 102 })
2927 "#]],
2928 );
2929}
2930
2931#[test]
2932fn disallow_duplicate_intrinsic_and_non_intrinsic_collision() {
2933 check(
2934 indoc! {"
2935 namespace A {
2936 internal operation C() : Unit {
2937 body intrinsic;
2938 }
2939 }
2940 namespace B {
2941 operation C() : Unit {}
2942 }
2943 namespace B {
2944 operation C() : Unit {
2945 body intrinsic;
2946 }
2947 }
2948 "},
2949 &expect![[r#"
2950 namespace namespace3 {
2951 internal operation item1() : Unit {
2952 body intrinsic;
2953 }
2954 }
2955 namespace namespace4 {
2956 operation item3() : Unit {}
2957 }
2958 namespace namespace4 {
2959 operation item5() : Unit {
2960 body intrinsic;
2961 }
2962 }
2963
2964 // Duplicate("C", "B", Span { lo: 154, hi: 155 })
2965 // DuplicateIntrinsic("C", Span { lo: 154, hi: 155 })
2966 "#]],
2967 );
2968}
2969
2970#[test]
2971fn disallow_duplicate_intrinsic_and_simulatableintrinsic() {
2972 check(
2973 indoc! {"
2974 namespace A {
2975 operation C() : Unit {
2976 body intrinsic;
2977 }
2978 }
2979 namespace B {
2980 @SimulatableIntrinsic()
2981 operation C() : Unit {}
2982 }
2983 "},
2984 &expect![[r#"
2985 namespace namespace3 {
2986 operation item1() : Unit {
2987 body intrinsic;
2988 }
2989 }
2990 namespace namespace4 {
2991 @SimulatableIntrinsic()
2992 operation item3() : Unit {}
2993 }
2994
2995 // DuplicateIntrinsic("C", Span { lo: 129, hi: 130 })
2996 "#]],
2997 );
2998}
2999
3000#[allow(clippy::cast_possible_truncation)]
3001fn check_locals(input: &str, expect: &Expect) {
3002 let parts = input.split('↘').collect::<Vec<_>>();
3003 assert_eq!(
3004 parts.len(),
3005 2,
3006 "input must contain exactly one cursor marker"
3007 );
3008 let cursor_offset = parts[0].len() as u32;
3009 let source = parts.join("");
3010
3011 let (_, _, locals, _, _) = compile(
3012 &source,
3013 LanguageFeatures::default(),
3014 TargetCapabilityFlags::all(),
3015 );
3016
3017 let locals = locals.get_all_at_offset(cursor_offset);
3018 let actual = locals.iter().fold(String::new(), |mut output, l| {
3019 let _ = writeln!(
3020 output,
3021 "{} ({})",
3022 l.name,
3023 match l.kind {
3024 LocalKind::Item(item_id) => item_id.to_string(),
3025 LocalKind::TyParam(param_id) => format!("ty_param {param_id}"),
3026 LocalKind::Var(node_id) => format!("var {node_id}"),
3027 }
3028 );
3029 output
3030 });
3031
3032 expect.assert_eq(&actual);
3033}
3034
3035#[test]
3036fn get_locals_vars() {
3037 check_locals(
3038 indoc! {"
3039 namespace Foo {
3040 function A() : Int {
3041 let x = 0;
3042
3043 let y = 0;
3044 }
3045 }
3046 "},
3047 &expect![[r#"
3048 x (var 13)
3049 "#]],
3050 );
3051}
3052
3053#[test]
3054fn get_locals_vars_shadowing_same_scope() {
3055 check_locals(
3056 indoc! {r#"
3057 namespace Foo {
3058 function A() : Int {
3059 let x = 0;
3060 let x = "foo";
3061
3062 }
3063 }
3064 "#},
3065 &expect![[r#"
3066 x (var 17)
3067 "#]],
3068 );
3069}
3070
3071#[test]
3072fn get_locals_vars_parent_scope() {
3073 check_locals(
3074 indoc! {r#"
3075 namespace Foo {
3076 function A() : Int {
3077 let x = 0;
3078 {
3079 let y = 0;
3080
3081 }
3082 }
3083 }
3084 "#},
3085 &expect![[r#"
3086 y (var 20)
3087 x (var 13)
3088 "#]],
3089 );
3090}
3091
3092#[test]
3093fn get_locals_params() {
3094 check_locals(
3095 indoc! {r#"
3096 namespace Foo {
3097 function A(x : Int) : Int {
3098
3099 }
3100 }
3101 "#},
3102 &expect![[r#"
3103 x (var 8)
3104 "#]],
3105 );
3106}
3107
3108#[test]
3109fn get_locals_spec_params() {
3110 check_locals(
3111 indoc! {"
3112 namespace Foo {
3113 operation A(q : Qubit) : (Qubit[], Qubit) {
3114 controlled (cs, ...) {
3115
3116 }
3117 }
3118 }
3119 "},
3120 &expect![[r#"
3121 cs (var 23)
3122 q (var 8)
3123 "#]],
3124 );
3125}
3126
3127#[test]
3128fn get_locals_before_binding() {
3129 check_locals(
3130 indoc! {"
3131 namespace Foo {
3132 function A() : Unit {
3133 let y = 0;
3134 let x = { ↘ };
3135 }
3136 }
3137 "},
3138 &expect![[r#"
3139 y (var 13)
3140 "#]],
3141 );
3142}
3143
3144#[test]
3145fn get_locals_lambda_params() {
3146 check_locals(
3147 indoc! {"
3148 namespace Foo {
3149 function A() : Unit {
3150 let y = 0;
3151 let f = x -> { ↘ };
3152 }
3153 }
3154 "},
3155 &expect![[r#"
3156 x (var 20)
3157 y (var 13)
3158 "#]],
3159 );
3160}
3161
3162#[test]
3163fn get_locals_for_loop() {
3164 check_locals(
3165 indoc! {"
3166 namespace Foo {
3167 function A() : Unit {
3168 for x in 0..1 {
3169
3170 }
3171 }
3172 }
3173 "},
3174 &expect![[r#"
3175 x (var 14)
3176 "#]],
3177 );
3178}
3179
3180#[test]
3181fn get_locals_for_loop_before_binding() {
3182 check_locals(
3183 indoc! {"
3184 namespace Foo {
3185 function A() : Unit {
3186 for x in 0..{ ↘ } {
3187 }
3188 }
3189 }
3190 "},
3191 &expect![""],
3192 );
3193}
3194
3195#[test]
3196fn get_locals_items() {
3197 check_locals(
3198 indoc! {"
3199 namespace Foo {
3200 function A() : Unit {
3201
3202 function B() : Unit {}
3203 newtype Bar = String;
3204 }
3205 }
3206 "},
3207 &expect![[r#"
3208 Bar (Item 3)
3209 B (Item 2)
3210 "#]],
3211 );
3212}
3213
3214#[test]
3215fn get_locals_local_item_hide_parent_scope_variables() {
3216 check_locals(
3217 indoc! {"
3218 namespace Foo {
3219 function A() : Unit {
3220 let x = 3;
3221 function B() : Unit {
3222 let y = 3;
3223
3224 }
3225 }
3226 }
3227 "},
3228 &expect![[r#"
3229 y (var 26)
3230 B (Item 2)
3231 "#]],
3232 );
3233}
3234
3235#[test]
3236fn get_locals_shadow_parent_scope() {
3237 check_locals(
3238 indoc! {r#"
3239 namespace Foo {
3240 function A() : Unit {
3241 let x = "foo";
3242 {
3243 let x = 0;
3244
3245 }
3246 }
3247 }
3248 "#},
3249 &expect![[r#"
3250 x (var 20)
3251 "#]],
3252 );
3253}
3254
3255#[test]
3256fn get_locals_type_params() {
3257 check_locals(
3258 indoc! {"
3259 namespace Foo {
3260 function A<'T>(t: 'T) : Unit {
3261 {
3262
3263 }
3264 }
3265 }
3266 "},
3267 &expect![[r#"
3268 t (var 9)
3269 'T (ty_param 0)
3270 "#]],
3271 );
3272}
3273
3274#[test]
3275fn get_locals_block_scope_boundary() {
3276 check_locals(
3277 indoc! {"
3278 namespace Foo {
3279 function A() : Int {
3280 {
3281 let x = 0;
3282 }↘
3283 }
3284 }
3285 "},
3286 &expect![""],
3287 );
3288}
3289
3290#[test]
3291fn get_locals_block_scope_boundary_begin() {
3292 check_locals(
3293 indoc! {"
3294 namespace Foo {
3295 function A() : Int {
3296 ↘{
3297 function Bar(): Unit {}
3298 }
3299 }
3300 }
3301 "},
3302 &expect![""],
3303 );
3304}
3305
3306#[test]
3307fn use_after_scope() {
3308 check(
3309 indoc! {"
3310 namespace Foo {
3311 function A() : Unit {
3312 {
3313 let x = 42;
3314 }
3315 x; // x should not be accessible here
3316 }
3317 }
3318 "},
3319 &expect![[r#"
3320 namespace namespace3 {
3321 function item1() : Unit {
3322 {
3323 let local16 = 42;
3324 }
3325 x; // x should not be accessible here
3326 }
3327 }
3328
3329 // NotFound("x", Span { lo: 94, hi: 95 })
3330 "#]],
3331 );
3332}
3333
3334#[test]
3335fn nested_function_definition() {
3336 check(
3337 indoc! {"
3338 namespace Foo {
3339 function A() : Unit {
3340 function B() : Unit {
3341 function C() : Unit {}
3342 C();
3343 }
3344 B();
3345 }
3346 }
3347 "},
3348 &expect![[r#"
3349 namespace namespace3 {
3350 function item1() : Unit {
3351 function item2() : Unit {
3352 function item3() : Unit {}
3353 item3();
3354 }
3355 item2();
3356 }
3357 }
3358 "#]],
3359 );
3360}
3361
3362#[test]
3363fn variable_in_nested_blocks() {
3364 check(
3365 indoc! {"
3366 namespace Foo {
3367 function A() : Unit {
3368 {
3369 let x = 10;
3370 {
3371 let y = x + 5;
3372 y; // Should be accessible
3373 }
3374 y; // Should not be accessible
3375 }
3376 }
3377 }
3378 "},
3379 &expect![[r#"
3380 namespace namespace3 {
3381 function item1() : Unit {
3382 {
3383 let local16 = 10;
3384 {
3385 let local23 = local16 + 5;
3386 local23; // Should be accessible
3387 }
3388 y; // Should not be accessible
3389 }
3390 }
3391 }
3392
3393 // NotFound("y", Span { lo: 190, hi: 191 })
3394 "#]],
3395 );
3396}
3397
3398#[test]
3399fn function_call_with_namespace_alias() {
3400 check(
3401 indoc! {"
3402 namespace Foo {
3403 function A() : Unit {}
3404 }
3405 namespace Bar {
3406 open Foo as F;
3407 function B() : Unit {
3408 F.A();
3409 }
3410 }
3411 "},
3412 &expect![[r#"
3413 namespace namespace3 {
3414 function item1() : Unit {}
3415 }
3416 namespace namespace4 {
3417 open namespace3 as F;
3418 function item3() : Unit {
3419 item1();
3420 }
3421 }
3422 "#]],
3423 );
3424}
3425
3426#[test]
3427fn type_alias_in_function_scope() {
3428 check(
3429 indoc! {"
3430 namespace Foo {
3431 function A() : Unit {
3432 newtype MyInt = Int;
3433 let x : MyInt = MyInt(5);
3434 }
3435 function B() : Unit {
3436 let z: MyInt = MyInt(5); // this should be a different type (and unresolved)
3437 }
3438 }
3439 "},
3440 &expect![[r#"
3441 namespace namespace3 {
3442 function item1() : Unit {
3443 newtype item3 = Int;
3444 let local20 : item3 = item3(5);
3445 }
3446 function item2() : Unit {
3447 let local40: MyInt = MyInt(5); // this should be a different type (and unresolved)
3448 }
3449 }
3450
3451 // NotFound("MyInt", Span { lo: 152, hi: 157 })
3452 // NotFound("MyInt", Span { lo: 160, hi: 165 })
3453 "#]],
3454 );
3455}
3456
3457#[test]
3458fn lambda_inside_lambda() {
3459 check(
3460 indoc! {"
3461 namespace Foo {
3462 function A() : Unit {
3463 let f = () -> {
3464 let g = (x) -> x + 1;
3465 g(10);
3466 };
3467 f();
3468 }
3469 }
3470 "},
3471 &expect![[r#"
3472 namespace namespace3 {
3473 function item1() : Unit {
3474 let local13 = () -> {
3475 let local20 = (local24) -> local24 + 1;
3476 local20(10);
3477 };
3478 local13();
3479 }
3480 }
3481 "#]],
3482 );
3483}
3484
3485#[test]
3486fn nested_namespaces_with_same_function_name() {
3487 check(
3488 indoc! {"
3489 namespace Foo {
3490 function A() : Unit {}
3491 }
3492 namespace Bar {
3493 function A() : Unit {}
3494 function B() : Unit {
3495 Foo.A();
3496 A(); // Should call Bar.A without needing to qualify
3497 }
3498 }
3499 "},
3500 &expect![[r#"
3501 namespace namespace3 {
3502 function item1() : Unit {}
3503 }
3504 namespace namespace4 {
3505 function item3() : Unit {}
3506 function item4() : Unit {
3507 item1();
3508 item3(); // Should call Bar.A without needing to qualify
3509 }
3510 }
3511 "#]],
3512 );
3513}
3514
3515#[test]
3516fn newtype_with_invalid_field_type() {
3517 check(
3518 indoc! {"
3519 namespace Foo {
3520 newtype Complex = (Re: Real, Im: Imaginary); // Imaginary is not a valid type
3521 }
3522 "},
3523 &expect![[r#"
3524 namespace namespace3 {
3525 newtype item1 = (Re: Real, Im: Imaginary); // Imaginary is not a valid type
3526 }
3527
3528 // NotFound("Real", Span { lo: 43, hi: 47 })
3529 // NotFound("Imaginary", Span { lo: 53, hi: 62 })
3530 "#]],
3531 );
3532}
3533
3534#[test]
3535fn newtype_with_tuple_destructuring() {
3536 check(
3537 indoc! {"
3538 namespace Foo {
3539 newtype Pair = (First: Int, Second: Int);
3540 function Destructure(pair: Pair) : Int {
3541 let (first, second) = pair;
3542 first + second
3543 }
3544 }
3545 "},
3546 &expect![[r#"
3547 namespace namespace3 {
3548 newtype item1 = (First: Int, Second: Int);
3549 function item2(local21: item1) : Int {
3550 let (local32, local34) = local21;
3551 local32 + local34
3552 }
3553 }
3554 "#]],
3555 );
3556}
3557
3558#[test]
3559fn items_resolve_according_to_implicit_hierarchy() {
3560 check(
3561 indoc! {"
3562namespace Foo {
3563 @EntryPoint()
3564 function Main(): Int {
3565 Foo()
3566 }
3567
3568 function Foo() : Int {
3569 Bar.Baz.Quux()
3570 }
3571}
3572
3573namespace Foo.Bar.Baz {
3574 function Quux() : Int { 6 }
3575}
3576"},
3577 &expect![[r#"
3578 namespace namespace3 {
3579 @EntryPoint()
3580 function item1(): Int {
3581 item2()
3582 }
3583
3584 function item2() : Int {
3585 item4()
3586 }
3587 }
3588
3589 namespace namespace5 {
3590 function item4() : Int { 6 }
3591 }
3592 "#]],
3593 );
3594}
3595
3596#[test]
3597fn basic_hierarchical_namespace() {
3598 check(
3599 indoc! {"
3600 namespace Foo.Bar.Baz {
3601 operation Quux() : Unit {}
3602 }
3603 namespace A {
3604 open Foo;
3605 operation Main() : Unit {
3606 Bar.Baz.Quux();
3607 }
3608 }
3609 namespace B {
3610 open Foo.Bar;
3611 operation Main() : Unit {
3612 Baz.Quux();
3613 }
3614 }"},
3615 &expect![[r#"
3616 namespace namespace5 {
3617 operation item1() : Unit {}
3618 }
3619 namespace namespace6 {
3620 open namespace3;
3621 operation item3() : Unit {
3622 item1();
3623 }
3624 }
3625 namespace namespace7 {
3626 open namespace4;
3627 operation item5() : Unit {
3628 item1();
3629 }
3630 }"#]],
3631 );
3632}
3633
3634#[test]
3635fn test_katas_shadowing_use_case() {
3636 check(
3637 indoc! {"namespace Kata {
3638 operation ApplyX() : Unit {
3639 // Do nothing.
3640 }
3641}
3642
3643namespace Kata.Verification {
3644 operation CheckSolution() : Bool {
3645 let _ = Kata.ApplyX();
3646 let _ = ApplyX();
3647 }
3648
3649 operation ApplyX() : Unit {}
3650}
3651" },
3652 &expect![[r#"
3653 namespace namespace3 {
3654 operation item1() : Unit {
3655 // Do nothing.
3656 }
3657 }
3658
3659 namespace namespace4 {
3660 operation item3() : Bool {
3661 let _ = item1();
3662 let _ = item4();
3663 }
3664
3665 operation item4() : Unit {}
3666 }
3667 "#]],
3668 );
3669}
3670
3671#[test]
3672fn open_can_access_parent_scope() {
3673 check(
3674 indoc! {r#"
3675namespace Foo.Bar {
3676 operation Hello() : Unit {
3677
3678 }
3679}
3680
3681namespace Foo {
3682 open Bar;
3683 @EntryPoint()
3684 operation Main() : Unit {
3685 Hello();
3686 }
3687}"#},
3688 &expect![[r#"
3689 namespace namespace4 {
3690 operation item1() : Unit {
3691
3692 }
3693 }
3694
3695 namespace namespace3 {
3696 open Bar;
3697 @EntryPoint()
3698 operation item3() : Unit {
3699 item1();
3700 }
3701 }"#]],
3702 );
3703}
3704
3705#[test]
3706fn test_export_statement() {
3707 check(
3708 indoc! {"namespace Foo {
3709 operation ApplyX() : Unit {
3710 }
3711 export ApplyX;
3712}
3713" },
3714 &expect![[r#"
3715 namespace namespace3 {
3716 operation item1() : Unit {
3717 }
3718 export item1;
3719 }
3720 "#]],
3721 );
3722}
3723
3724#[test]
3725fn test_complicated_nested_export_statement() {
3726 check(
3727 indoc! {
3728"
3729
3730namespace Foo {
3731 export Foo.Bar.Baz.Quux.HelloWorld;
3732}
3733namespace Foo.Bar.Baz.Quux {
3734 function HelloWorld() : Unit {}
3735}
3736
3737namespace Foo.Bar {
3738 export Baz.Quux.HelloWorld;
3739}
3740
3741namespace Foo.Bar.Baz {
3742 export Quux.HelloWorld;
3743}
3744
3745namespace Foo.Bar.Graule {
3746 // HelloWorld should be available from all namespaces
3747 operation Main() : Unit {
3748 Foo.Bar.Baz.Quux.HelloWorld();
3749 Foo.Bar.Baz.HelloWorld();
3750 Foo.Bar.HelloWorld();
3751 Foo.HelloWorld();
3752 open Foo;
3753 HelloWorld();
3754 }
3755 // and we should be able to re-export it
3756 export Foo.HelloWorld;
3757}" },
3758 &expect![[r#"
3759
3760 namespace namespace3 {
3761 export item2;
3762 }
3763 namespace namespace6 {
3764 function item2() : Unit {}
3765 }
3766
3767 namespace namespace4 {
3768 export item2;
3769 }
3770
3771 namespace namespace5 {
3772 export item2;
3773 }
3774
3775 namespace namespace7 {
3776 // HelloWorld should be available from all namespaces
3777 operation item6() : Unit {
3778 item2();
3779 item2();
3780 item2();
3781 item2();
3782 open namespace3;
3783 item2();
3784 }
3785 // and we should be able to re-export it
3786 export item2;
3787 }"#]],
3788 );
3789}
3790
3791#[test]
3792fn exports_aware_of_opens() {
3793 check(
3794 indoc! {r#"
3795 namespace Foo {
3796 operation F() : Unit {}
3797 }
3798 namespace Main {
3799 open Foo;
3800 export F;
3801 }
3802 "# },
3803 &expect![[r#"
3804 namespace namespace3 {
3805 operation item1() : Unit {}
3806 }
3807 namespace namespace4 {
3808 open namespace3;
3809 export item1;
3810 }
3811 "#]],
3812 );
3813}
3814
3815#[test]
3816fn export_symbol_and_call_it() {
3817 check(
3818 indoc! {
3819"
3820namespace Foo {
3821 export Foo.Bar.Baz.Quux.Function;
3822}
3823namespace Foo.Bar.Baz.Quux {
3824 function Function() : Unit {}
3825}
3826
3827namespace Main {
3828 open Foo;
3829 operation Main() : Unit {
3830 Foo.Function();
3831 Function();
3832 }
3833}" },
3834 &expect![[r#"
3835 namespace namespace3 {
3836 export item2;
3837 }
3838 namespace namespace6 {
3839 function item2() : Unit {}
3840 }
3841
3842 namespace namespace7 {
3843 open namespace3;
3844 operation item4() : Unit {
3845 item2();
3846 item2();
3847 }
3848 }"#]],
3849 );
3850}
3851
3852#[test]
3853fn multiple_exports() {
3854 check(
3855 indoc! {"
3856 namespace Foo {
3857 operation ApplyX() : Unit {}
3858 operation ApplyY() : Unit {}
3859 }
3860 namespace Main {
3861 import Foo.ApplyX as X, Foo.ApplyY as Y;
3862 operation Main() : Unit {
3863 X();
3864 Y();
3865 }
3866 }
3867 "},
3868 &expect![[r#"
3869 namespace namespace3 {
3870 operation item1() : Unit {}
3871 operation item2() : Unit {}
3872 }
3873 namespace namespace4 {
3874 import item1, item2;
3875 operation item4() : Unit {
3876 item1();
3877 item2();
3878 }
3879 }
3880 "#]],
3881 );
3882}
3883
3884#[test]
3885fn no_exports() {
3886 check(
3887 indoc! {"
3888 namespace Foo {
3889 operation ApplyX() : Unit {}
3890 }
3891 namespace Main {
3892 open Foo;
3893 operation Main() : Unit {
3894 ApplyX();
3895 }
3896 }
3897 "},
3898 &expect![[r#"
3899 namespace namespace3 {
3900 operation item1() : Unit {}
3901 }
3902 namespace namespace4 {
3903 open namespace3;
3904 operation item3() : Unit {
3905 item1();
3906 }
3907 }
3908 "#]],
3909 );
3910}
3911
3912#[test]
3913fn export_non_existent_symbol() {
3914 check(
3915 indoc! {"
3916 namespace Foo {
3917 export NonExistent;
3918 }
3919 "},
3920 &expect![[r#"
3921 namespace namespace3 {
3922 export NonExistent;
3923 }
3924
3925 // NotFound("NonExistent", Span { lo: 27, hi: 38 })
3926 "#]],
3927 );
3928}
3929
3930#[test]
3931fn export_symbol_from_nested_namespace() {
3932 check(
3933 indoc! {"
3934 namespace Foo.Bar {
3935 operation ApplyX() : Unit {}
3936 }
3937 namespace Foo {
3938 export Bar.ApplyX;
3939 }
3940 namespace Main {
3941 open Foo;
3942 operation Main() : Unit {
3943 Bar.ApplyX();
3944 }
3945 }
3946 "},
3947 &expect![[r#"
3948 namespace namespace4 {
3949 operation item1() : Unit {}
3950 }
3951 namespace namespace3 {
3952 export item1;
3953 }
3954 namespace namespace5 {
3955 open namespace3;
3956 operation item4() : Unit {
3957 item1();
3958 }
3959 }
3960 "#]],
3961 );
3962}
3963
3964#[test]
3965fn disallow_exporting_local_vars() {
3966 check(
3967 indoc! {"
3968 namespace Foo {
3969 operation Main() : Unit {
3970 let x = 5;
3971 }
3972 export x;
3973 }
3974 "},
3975 &expect![[r#"
3976 namespace namespace3 {
3977 operation item1() : Unit {
3978 let local13 = 5;
3979 }
3980 export x;
3981 }
3982
3983 // NotFound("x", Span { lo: 82, hi: 83 })
3984 "#]],
3985 );
3986}
3987
3988#[test]
3989fn export_non_item() {
3990 check(
3991 indoc! {"
3992 namespace Bar {}
3993 namespace Foo {
3994 operation Main() : Unit {
3995 }
3996 export Unit;
3997
3998 }
3999 "},
4000 &expect![[r#"
4001 namespace namespace3 {}
4002 namespace namespace4 {
4003 operation item2() : Unit {
4004 }
4005 export Unit;
4006
4007 }
4008 "#]],
4009 );
4010}
4011
4012#[test]
4013fn export_udt() {
4014 check(
4015 indoc! {"
4016 namespace Foo {
4017 newtype Pair = (First: Int, Second: Int);
4018 export Pair;
4019 }
4020 namespace Main {
4021 open Foo;
4022 operation Main() : Unit {
4023 Pair(1, 2);
4024 }
4025 }
4026 "},
4027 &expect![[r#"
4028 namespace namespace3 {
4029 newtype item1 = (First: Int, Second: Int);
4030 export item1;
4031 }
4032 namespace namespace4 {
4033 open namespace3;
4034 operation item3() : Unit {
4035 item1(1, 2);
4036 }
4037 }
4038 "#]],
4039 );
4040}
4041
4042#[test]
4043fn export_with_alias() {
4044 check(
4045 indoc! {"
4046 namespace Foo {
4047 operation ApplyX() : Unit {}
4048 export ApplyX as SomeAlias;
4049 }
4050 namespace Main {
4051 open Foo;
4052 operation Main() : Unit {
4053 SomeAlias();
4054 }
4055 }
4056 "},
4057 &expect![[r#"
4058 namespace namespace3 {
4059 operation item1() : Unit {}
4060 export item1;
4061 }
4062 namespace namespace4 {
4063 open namespace3;
4064 operation item3() : Unit {
4065 item1();
4066 }
4067 }
4068 "#]],
4069 );
4070}
4071
4072#[test]
4073fn multiple_exports_with_aliases() {
4074 check(
4075 indoc! {"
4076 namespace Foo {
4077 operation ApplyX() : Unit {}
4078 operation ApplyY() : Unit {}
4079 export ApplyX as SomeAlias, ApplyY as AnotherAlias;
4080 }
4081 namespace Main {
4082 open Foo;
4083 operation Main() : Unit {
4084 SomeAlias();
4085 AnotherAlias();
4086 }
4087 }
4088 "},
4089 &expect![[r#"
4090 namespace namespace3 {
4091 operation item1() : Unit {}
4092 operation item2() : Unit {}
4093 export item1, item2;
4094 }
4095 namespace namespace4 {
4096 open namespace3;
4097 operation item4() : Unit {
4098 item1();
4099 item2();
4100 }
4101 }
4102 "#]],
4103 );
4104}
4105
4106#[test]
4107fn aliased_exports_call_with_qualified_paths() {
4108 check(
4109 indoc! {"
4110 namespace Foo {
4111 operation ApplyX() : Unit {}
4112 operation ApplyY() : Unit {}
4113 export ApplyX as SomeAlias, ApplyY as AnotherAlias;
4114 }
4115 namespace Main {
4116 open Foo;
4117 operation Main() : Unit {
4118 Foo.SomeAlias();
4119 Foo.AnotherAlias();
4120 }
4121 }
4122 "},
4123 &expect![[r#"
4124 namespace namespace3 {
4125 operation item1() : Unit {}
4126 operation item2() : Unit {}
4127 export item1, item2;
4128 }
4129 namespace namespace4 {
4130 open namespace3;
4131 operation item4() : Unit {
4132 item1();
4133 item2();
4134 }
4135 }
4136 "#]],
4137 );
4138}
4139
4140#[test]
4141fn reexport_from_full_path_with_alias() {
4142 check(
4143 indoc! {"
4144 namespace Foo {
4145 operation ApplyX() : Unit {}
4146 export ApplyX as SomeAlias;
4147 }
4148 namespace Main {
4149 open Foo;
4150 export Foo.SomeAlias as AnotherAlias;
4151 }
4152 "},
4153 &expect![[r#"
4154 namespace namespace3 {
4155 operation item1() : Unit {}
4156 export item1;
4157 }
4158 namespace namespace4 {
4159 open namespace3;
4160 export item1;
4161 }
4162 "#]],
4163 );
4164}
4165
4166#[test]
4167fn disallow_repeated_exports() {
4168 check(
4169 indoc! {"
4170 namespace Foo {
4171 operation ApplyX() : Unit {}
4172 export ApplyX;
4173 export ApplyX;
4174 }
4175 "},
4176 &expect![[r#"
4177 namespace namespace3 {
4178 operation item1() : Unit {}
4179 export item1;
4180 export item1;
4181 }
4182
4183 // DuplicateExport("ApplyX", Span { lo: 79, hi: 85 })
4184 "#]],
4185 );
4186}
4187
4188#[test]
4189fn disallow_repeated_exports_inline() {
4190 check(
4191 indoc! {"
4192 namespace Foo {
4193 operation ApplyX() : Unit {}
4194 export ApplyX, ApplyX;
4195 }
4196 "},
4197 &expect![[r#"
4198 namespace namespace3 {
4199 operation item1() : Unit {}
4200 export item1, item1;
4201 }
4202
4203 // DuplicateExport("ApplyX", Span { lo: 68, hi: 74 })
4204 "#]],
4205 );
4206}
4207
4208#[test]
4209fn order_of_exports_does_not_matter() {
4210 check(
4211 indoc! {"
4212 namespace Bar {
4213 export Foo.ApplyX;
4214 export ApplyY;
4215 operation ApplyY() : Unit {}
4216 }
4217 namespace Foo {
4218 operation ApplyX() : Unit {}
4219 }
4220
4221 "},
4222 &expect![[r#"
4223 namespace namespace3 {
4224 export item3;
4225 export item1;
4226 operation item1() : Unit {}
4227 }
4228 namespace namespace4 {
4229 operation item3() : Unit {}
4230 }
4231
4232 "#]],
4233 );
4234}
4235
4236#[test]
4237fn export_udt_and_construct_it() {
4238 check(
4239 indoc! {"
4240 namespace Foo {
4241 newtype Pair = (First: Int, Second: Int);
4242 export Pair;
4243 }
4244 namespace Main {
4245 open Foo;
4246 operation Main() : Unit {
4247 let z: Pair = Pair(1, 2);
4248 }
4249 }
4250 "},
4251 &expect![[r#"
4252 namespace namespace3 {
4253 newtype item1 = (First: Int, Second: Int);
4254 export item1;
4255 }
4256 namespace namespace4 {
4257 open namespace3;
4258 operation item3() : Unit {
4259 let local34: item1 = item1(1, 2);
4260 }
4261 }
4262 "#]],
4263 );
4264}
4265#[test]
4266fn import_single_item() {
4267 check(
4268 indoc! {"
4269 namespace Foo {
4270 function Bar() : Unit {}
4271 }
4272 namespace Main {
4273 import Foo.Bar;
4274 operation Main() : Unit {
4275 Bar();
4276 }
4277 }
4278 "},
4279 &expect![[r#"
4280 namespace namespace3 {
4281 function item1() : Unit {}
4282 }
4283 namespace namespace4 {
4284 import item1;
4285 operation item3() : Unit {
4286 item1();
4287 }
4288 }
4289 "#]],
4290 );
4291}
4292
4293#[test]
4294fn import_namespace() {
4295 check(
4296 indoc! {"
4297 namespace Foo.Bar {
4298 function Baz() : Unit {}
4299 }
4300 namespace Main {
4301 import Foo.Bar;
4302 operation Main() : Unit {
4303 Bar.Baz();
4304 }
4305 }
4306 "},
4307 &expect![[r#"
4308 namespace namespace4 {
4309 function item1() : Unit {}
4310 }
4311 namespace namespace5 {
4312 import namespace4;
4313 operation item3() : Unit {
4314 item1();
4315 }
4316 }
4317 "#]],
4318 );
4319}
4320
4321#[test]
4322fn import_non_existent_item() {
4323 check(
4324 indoc! {"
4325 namespace Foo {
4326 }
4327 namespace Main {
4328 import Foo.Bar;
4329 operation Main() : Unit {
4330 Bar();
4331 }
4332 }
4333 "},
4334 &expect![[r#"
4335 namespace namespace3 {
4336 }
4337 namespace namespace4 {
4338 import Foo.Bar;
4339 operation item2() : Unit {
4340 Bar();
4341 }
4342 }
4343
4344 // NotFound("Foo.Bar", Span { lo: 46, hi: 53 })
4345 // NotFound("Bar", Span { lo: 93, hi: 96 })
4346 "#]],
4347 );
4348}
4349
4350#[test]
4351fn import_shadowing() {
4352 check(
4353 indoc! {"
4354 namespace Foo {
4355 function Bar() : Unit {}
4356 }
4357 namespace Main {
4358 function Bar() : Unit {}
4359 import Foo.Bar;
4360 operation Main() : Unit {
4361 Bar();
4362 }
4363 }
4364 "},
4365 &expect![[r#"
4366 namespace namespace3 {
4367 function item1() : Unit {}
4368 }
4369 namespace namespace4 {
4370 function item3() : Unit {}
4371 import item1;
4372 operation item4() : Unit {
4373 item1();
4374 }
4375 }
4376 "#]],
4377 );
4378}
4379
4380#[test]
4381fn import_with_alias() {
4382 check(
4383 indoc! {"
4384 namespace Foo {
4385 function Bar() : Unit {}
4386 }
4387 namespace Main {
4388 import Foo.Bar as Baz;
4389 operation Main() : Unit {
4390 Baz();
4391 }
4392 }
4393 "},
4394 &expect![[r#"
4395 namespace namespace3 {
4396 function item1() : Unit {}
4397 }
4398 namespace namespace4 {
4399 import item1;
4400 operation item3() : Unit {
4401 item1();
4402 }
4403 }
4404 "#]],
4405 );
4406}
4407
4408#[test]
4409fn import_non_item() {
4410 check(
4411 indoc! {"
4412 namespace Main {
4413 import Unit;
4414 operation Main() : Unit {
4415 }
4416 }
4417 "},
4418 &expect![[r#"
4419 namespace namespace3 {
4420 import Unit;
4421 operation item1() : Unit {
4422 }
4423 }
4424 "#]],
4425 );
4426}
4427
4428#[test]
4429fn import_namespace_nested() {
4430 check(
4431 indoc! {"
4432 namespace Foo.Bar.Baz {
4433 operation Quux() : Unit {}
4434 }
4435 namespace Main {
4436 import Foo.Bar;
4437 operation Main() : Unit {
4438 Bar.Baz.Quux();
4439 }
4440 }
4441 "},
4442 &expect![[r#"
4443 namespace namespace5 {
4444 operation item1() : Unit {}
4445 }
4446 namespace namespace6 {
4447 import namespace4;
4448 operation item3() : Unit {
4449 item1();
4450 }
4451 }
4452 "#]],
4453 );
4454}
4455
4456#[test]
4457fn import_single_namespace() {
4458 check(
4459 indoc! {"
4460 namespace Foo {
4461 operation Bar() : Unit {}
4462 }
4463 namespace Main {
4464 import Foo;
4465
4466 operation Main() : Unit {
4467 Foo.Bar();
4468 }
4469 }
4470 "},
4471 &expect![[r#"
4472 namespace namespace3 {
4473 operation item1() : Unit {}
4474 }
4475 namespace namespace4 {
4476 import namespace3;
4477
4478 operation item3() : Unit {
4479 item1();
4480 }
4481 }
4482 "#]],
4483 );
4484}
4485
4486#[test]
4487fn import_shadowing_function() {
4488 check(
4489 indoc! {"
4490 namespace Foo {
4491 operation Bar() : Unit {}
4492 }
4493 namespace Main {
4494 operation Bar() : Unit {}
4495 operation Main() : Unit {
4496 import Foo.Bar;
4497 Bar();
4498 }
4499 }
4500 "},
4501 &expect![[r#"
4502 namespace namespace3 {
4503 operation item1() : Unit {}
4504 }
4505 namespace namespace4 {
4506 operation item3() : Unit {}
4507 operation item4() : Unit {
4508 import item1;
4509 item1();
4510 }
4511 }
4512 "#]],
4513 );
4514}
4515
4516#[test]
4517fn import_non_existent_namespace() {
4518 check(
4519 indoc! {"
4520 namespace Main {
4521 operation Main() : Unit {
4522 import NonExistent;
4523 }
4524 }
4525 "},
4526 &expect![[r#"
4527 namespace namespace3 {
4528 operation item1() : Unit {
4529 import NonExistent;
4530 }
4531 }
4532
4533 // NotFound("NonExistent", Span { lo: 62, hi: 73 })
4534 "#]],
4535 );
4536}
4537
4538#[test]
4539fn import_self() {
4540 check(
4541 indoc! {"
4542 namespace Main {
4543 operation Foo() : Unit {
4544 import Foo;
4545 }
4546 }
4547 "},
4548 &expect![[r#"
4549 namespace namespace3 {
4550 operation item1() : Unit {
4551 import item1;
4552 }
4553 }
4554 "#]],
4555 );
4556}
4557
4558// this should be allowed for jupyter cell re-runnability
4559#[test]
4560fn import_duplicate_symbol() {
4561 check(
4562 indoc! { r#"
4563 namespace Main {
4564 import Foo.Bar.Baz, Foo.Bar.Baz;
4565 }
4566 namespace Foo.Bar {
4567 operation Baz() : Unit {}
4568 }
4569"# },
4570 &expect![[r#"
4571 namespace namespace3 {
4572 import item2, item2;
4573 }
4574 namespace namespace5 {
4575 operation item2() : Unit {}
4576 }
4577 "#]],
4578 );
4579}
4580
4581// this should be allowed for jupyter cell re-runnability
4582#[test]
4583fn import_duplicate_symbol_different_name() {
4584 check(
4585 indoc! { r#"
4586 namespace Main {
4587 import Foo.Bar.Baz, Foo.Bar;
4588 import Bar.Baz;
4589 }
4590 namespace Foo.Bar {
4591 operation Baz() : Unit {}
4592 }
4593"# },
4594 &expect![[r#"
4595 namespace namespace3 {
4596 import item2, namespace5;
4597 import item2;
4598 }
4599 namespace namespace5 {
4600 operation item2() : Unit {}
4601 }
4602 "#]],
4603 );
4604}
4605
4606// this should be allowed for jupyter cell re-runnability
4607#[test]
4608fn disallow_importing_different_items_with_same_name() {
4609 check(
4610 indoc! { r#"
4611 namespace Main {
4612 import Foo.Bar.Baz, Foo.Bar.Baz2 as Baz;
4613 }
4614 namespace Foo.Bar {
4615 operation Baz() : Unit {}
4616 operation Baz2() : Unit {}
4617 }
4618"# },
4619 &expect![[r#"
4620 namespace namespace3 {
4621 import item2, item3;
4622 }
4623 namespace namespace5 {
4624 operation item2() : Unit {}
4625 operation item3() : Unit {}
4626 }
4627
4628 // ImportedDuplicate("Baz", Span { lo: 57, hi: 60 })
4629 "#]],
4630 );
4631}
4632
4633#[test]
4634fn import_takes_precedence_over_local_decl() {
4635 check(
4636 indoc! { r#"
4637 namespace Main {
4638
4639 operation Baz() : Unit {
4640 import Foo.Bar.Baz;
4641 Baz();
4642 }
4643
4644 }
4645
4646 namespace Foo.Bar {
4647 operation Baz() : Unit {}
4648 }
4649"# },
4650 &expect![[r#"
4651 namespace namespace3 {
4652
4653 operation item1() : Unit {
4654 import item3;
4655 item3();
4656 }
4657
4658 }
4659
4660 namespace namespace5 {
4661 operation item3() : Unit {}
4662 }
4663 "#]],
4664 );
4665}
4666
4667#[test]
4668fn import_then_export() {
4669 check(
4670 indoc! {"
4671 namespace Foo {
4672 operation Bar() : Unit {}
4673 }
4674 namespace Main {
4675 import Foo.Bar;
4676 export Bar;
4677 }
4678 "},
4679 &expect![[r#"
4680 namespace namespace3 {
4681 operation item1() : Unit {}
4682 }
4683 namespace namespace4 {
4684 import item1;
4685 export item1;
4686 }
4687 "#]],
4688 );
4689}
4690
4691#[test]
4692fn import_namespace_advanced() {
4693 check(
4694 indoc! {"
4695 namespace A.B.C.D.E {
4696 operation DumpMachine() : Unit {}
4697 }
4698 namespace TestOne {
4699 import A;
4700 operation Main() : Unit {
4701 A.B.C.D.E.DumpMachine();
4702 }
4703 }
4704 namespace TestTwo {
4705 import A.B;
4706 operation Main() : Unit {
4707 B.C.D.E.DumpMachine();
4708 }
4709 }
4710 namespace TestThree {
4711 import A.B.C;
4712 operation Main() : Unit {
4713 C.D.E.DumpMachine();
4714 }
4715 }
4716 namespace TestFour {
4717 import A.B.C.D;
4718 operation Main() : Unit {
4719 D.E.DumpMachine();
4720 }
4721 }
4722 namespace TestFive {
4723 import A.B.C.D.E;
4724 operation Main() : Unit {
4725 E.DumpMachine();
4726 }
4727 }
4728 namespace TestSix {
4729 import A.B.C.D.E.DumpMachine;
4730 operation Main() : Unit {
4731 DumpMachine();
4732 }
4733 }
4734 "},
4735 &expect![[r#"
4736 namespace namespace7 {
4737 operation item1() : Unit {}
4738 }
4739 namespace namespace8 {
4740 import namespace3;
4741 operation item3() : Unit {
4742 item1();
4743 }
4744 }
4745 namespace namespace9 {
4746 import namespace4;
4747 operation item5() : Unit {
4748 item1();
4749 }
4750 }
4751 namespace namespace10 {
4752 import namespace5;
4753 operation item7() : Unit {
4754 item1();
4755 }
4756 }
4757 namespace namespace11 {
4758 import namespace6;
4759 operation item9() : Unit {
4760 item1();
4761 }
4762 }
4763 namespace namespace12 {
4764 import namespace7;
4765 operation item11() : Unit {
4766 item1();
4767 }
4768 }
4769 namespace namespace13 {
4770 import item1;
4771 operation item13() : Unit {
4772 item1();
4773 }
4774 }
4775 "#]],
4776 );
4777}
4778
4779#[test]
4780fn import_namespace_does_not_open_it() {
4781 check(
4782 indoc! {"
4783 namespace Microsoft.Quantum.Diagnostics {
4784 operation DumpMachine() : Unit {}
4785 }
4786 namespace Main {
4787 import Microsoft.Quantum.Diagnostics;
4788 operation Main() : Unit {
4789 Diagnostics.DumpMachine();
4790 DumpMachine();
4791 }
4792 }
4793 "},
4794 &expect![[r#"
4795 namespace namespace5 {
4796 operation item1() : Unit {}
4797 }
4798 namespace namespace6 {
4799 import namespace5;
4800 operation item3() : Unit {
4801 item1();
4802 DumpMachine();
4803 }
4804 }
4805
4806 // NotFound("DumpMachine", Span { lo: 214, hi: 225 })
4807 "#]],
4808 );
4809}
4810
4811#[test]
4812fn invalid_import() {
4813 check(
4814 indoc! {"
4815 namespace Main {
4816 import A.B.C;
4817 operation Main() : Unit {
4818 }
4819 }
4820 "},
4821 &expect![[r#"
4822 namespace namespace3 {
4823 import A.B.C;
4824 operation item1() : Unit {
4825 }
4826 }
4827
4828 // NotFound("A.B.C", Span { lo: 28, hi: 33 })
4829 "#]],
4830 );
4831}
4832
4833#[test]
4834fn export_namespace() {
4835 check(
4836 indoc! {"
4837 namespace Foo {
4838 operation ApplyX() : Unit {}
4839 operation ApplyY() : Unit {}
4840 }
4841 namespace Main {
4842 export Foo;
4843 }
4844 namespace Test {
4845 open Main.Foo;
4846 operation Main() : Unit {
4847 ApplyX();
4848 ApplyY();
4849 }
4850 }
4851 "},
4852 &expect![[r#"
4853 namespace namespace3 {
4854 operation item1() : Unit {}
4855 operation item2() : Unit {}
4856 }
4857 namespace namespace4 {
4858 export item4;
4859 }
4860 namespace namespace5 {
4861 open namespace3;
4862 operation item6() : Unit {
4863 item1();
4864 item2();
4865 }
4866 }
4867 "#]],
4868 );
4869}
4870
4871#[test]
4872fn export_namespace_contains_children() {
4873 check(
4874 indoc! {"
4875 namespace Foo.Bar {
4876 operation ApplyX() : Unit {}
4877 }
4878 namespace Main {
4879 export Foo;
4880 }
4881 namespace Test {
4882 open Main.Foo.Bar;
4883 operation Main() : Unit {
4884 ApplyX();
4885 }
4886 }
4887 "},
4888 &expect![[r#"
4889 namespace namespace4 {
4890 operation item1() : Unit {}
4891 }
4892 namespace namespace5 {
4893 export item3;
4894 }
4895 namespace namespace6 {
4896 open namespace4;
4897 operation item5() : Unit {
4898 item1();
4899 }
4900 }
4901 "#]],
4902 );
4903}
4904
4905#[test]
4906fn export_namespace_cyclic() {
4907 check(
4908 indoc! {"
4909 namespace Foo {
4910 export Bar;
4911 }
4912 namespace Bar {
4913 export Foo;
4914 operation Hello() : Unit {}
4915 }
4916 namespace Main {
4917 open Foo.Bar.Foo.Bar.Foo.Bar;
4918 operation Main() : Unit { Hello(); }
4919 }
4920 "},
4921 &expect![[r#"
4922 namespace namespace3 {
4923 export namespace4;
4924 }
4925 namespace namespace4 {
4926 export item2;
4927 operation item3() : Unit {}
4928 }
4929 namespace namespace5 {
4930 open namespace4;
4931 operation item5() : Unit { item3(); }
4932 }
4933 "#]],
4934 );
4935}
4936
4937#[test]
4938fn export_direct_cycle() {
4939 check(
4940 indoc! {"
4941 namespace Foo {
4942 export Foo;
4943 }
4944
4945 namespace Main {
4946 open Foo.Foo.Foo.Foo.Foo;
4947 operation Main() : Unit { }
4948 }
4949 "},
4950 &expect![[r#"
4951 namespace namespace3 {
4952 export namespace3;
4953 }
4954
4955 namespace namespace4 {
4956 open namespace3;
4957 operation item2() : Unit { }
4958 }
4959 "#]],
4960 );
4961}
4962
4963#[test]
4964fn export_namespace_with_alias() {
4965 check(
4966 indoc! {"
4967 namespace Foo.Bar {
4968 operation ApplyX() : Unit {}
4969 }
4970 namespace Main {
4971 export Foo.Bar as Baz;
4972 }
4973 namespace Test {
4974 open Main.Baz;
4975 operation Main() : Unit {
4976 ApplyX();
4977 Main.Baz.ApplyX();
4978 }
4979 }
4980 "},
4981 &expect![[r#"
4982 namespace namespace4 {
4983 operation item1() : Unit {}
4984 }
4985 namespace namespace5 {
4986 export namespace4;
4987 }
4988 namespace namespace6 {
4989 open namespace4;
4990 operation item5() : Unit {
4991 item1();
4992 item1();
4993 }
4994 }
4995 "#]],
4996 );
4997}
4998
4999#[test]
5000fn import_glob() {
5001 check(
5002 indoc! {"
5003 namespace Foo {
5004 operation ApplyX() : Unit {}
5005 operation ApplyY() : Unit {}
5006 }
5007 namespace Main {
5008 import Foo.*;
5009 operation Main() : Unit {
5010 ApplyX();
5011 ApplyY();
5012 }
5013 }
5014 "},
5015 &expect![[r#"
5016 namespace namespace3 {
5017 operation item1() : Unit {}
5018 operation item2() : Unit {}
5019 }
5020 namespace namespace4 {
5021 import namespace3.*;
5022 operation item4() : Unit {
5023 item1();
5024 item2();
5025 }
5026 }
5027 "#]],
5028 );
5029}
5030
5031#[test]
5032fn import_aliased_glob() {
5033 check(
5034 indoc! {"
5035 namespace Foo {
5036 operation ApplyX() : Unit {}
5037 operation ApplyY() : Unit {}
5038 }
5039 namespace Main {
5040 import Foo as Bar;
5041 operation Main() : Unit {
5042 Bar.ApplyX();
5043 Bar.ApplyY();
5044 }
5045 }
5046 "},
5047 &expect![[r#"
5048 namespace namespace3 {
5049 operation item1() : Unit {}
5050 operation item2() : Unit {}
5051 }
5052 namespace namespace4 {
5053 import namespace3;
5054 operation item4() : Unit {
5055 item1();
5056 item2();
5057 }
5058 }
5059 "#]],
5060 );
5061}
5062
5063#[test]
5064fn disallow_glob_export() {
5065 check(
5066 indoc! {"
5067 namespace Foo {
5068 operation ApplyX() : Unit {}
5069 operation ApplyY() : Unit {}
5070 }
5071 namespace Bar {
5072 export Foo.*;
5073 }
5074 "},
5075 &expect![[r#"
5076 namespace namespace3 {
5077 operation item1() : Unit {}
5078 operation item2() : Unit {}
5079 }
5080 namespace namespace4 {
5081 export namespace3.*;
5082 }
5083
5084 // GlobExportNotSupported(Span { lo: 111, hi: 114 })
5085 "#]],
5086 );
5087}
5088
5089#[test]
5090fn import_glob_in_list() {
5091 check(
5092 indoc! {"
5093 namespace Foo.Bar {
5094 operation ApplyX() : Unit {}
5095 operation ApplyY() : Unit {}
5096 }
5097 namespace Foo.Bar.Baz {
5098 operation ApplyZ() : Unit {}
5099 }
5100 namespace Main {
5101 import Foo.Bar.*, Foo.Bar.Baz.ApplyZ;
5102 operation Main() : Unit {
5103 ApplyX();
5104 ApplyY();
5105 Baz.ApplyZ();
5106 ApplyZ();
5107 }
5108 }
5109 "},
5110 &expect![[r#"
5111 namespace namespace4 {
5112 operation item1() : Unit {}
5113 operation item2() : Unit {}
5114 }
5115 namespace namespace5 {
5116 operation item4() : Unit {}
5117 }
5118 namespace namespace6 {
5119 import namespace4.*, item4;
5120 operation item6() : Unit {
5121 item1();
5122 item2();
5123 item4();
5124 item4();
5125 }
5126 }
5127 "#]],
5128 );
5129}
5130
5131#[test]
5132fn import_glob_in_list_with_alias() {
5133 check(
5134 indoc! {"
5135 namespace Foo.Bar {
5136 operation ApplyX() : Unit {}
5137 operation ApplyY() : Unit {}
5138 }
5139 namespace Foo.Bar.Baz {
5140 operation ApplyZ() : Unit {}
5141 }
5142 namespace Main {
5143 import Foo.Bar as Alias, Foo.Bar.Baz.ApplyZ as Foo;
5144 operation Main() : Unit {
5145 Alias.ApplyX();
5146 Alias.ApplyY();
5147 Alias.Baz.ApplyZ();
5148 Foo();
5149 }
5150 }
5151 "},
5152 &expect![[r#"
5153 namespace namespace4 {
5154 operation item1() : Unit {}
5155 operation item2() : Unit {}
5156 }
5157 namespace namespace5 {
5158 operation item4() : Unit {}
5159 }
5160 namespace namespace6 {
5161 import namespace4, item4;
5162 operation item6() : Unit {
5163 item1();
5164 item2();
5165 item4();
5166 item4();
5167 }
5168 }
5169 "#]],
5170 );
5171}
5172
5173#[test]
5174fn import_newtype() {
5175 check(
5176 indoc! {r#"
5177 namespace Foo {
5178 import Bar.NewType; // no error
5179
5180 operation FooOperation() : Unit {
5181 let x: NewType = NewType("a");
5182 }
5183 }
5184
5185 namespace Bar {
5186 newtype NewType = String;
5187 export NewType;
5188
5189 }"#},
5190 &expect![[r#"
5191 namespace namespace3 {
5192 import item3; // no error
5193
5194 operation item1() : Unit {
5195 let local17: item3 = item3("a");
5196 }
5197 }
5198
5199 namespace namespace4 {
5200 newtype item3 = String;
5201 export item3;
5202
5203 }"#]],
5204 );
5205}
5206
5207#[test]
5208fn disallow_glob_alias_import() {
5209 check(
5210 indoc! {r#"
5211 namespace Bar {}
5212 namespace Main {
5213 import Bar.* as B;
5214 }
5215 "#},
5216 &expect![[r#"
5217 namespace namespace3 {}
5218 namespace namespace4 {
5219 import namespace3;
5220 }
5221
5222 // GlobImportAliasNotSupported { namespace_name: "Bar", alias: "B", span: Span { lo: 45, hi: 55 } }
5223 "#]],
5224 );
5225}
5226
5227#[test]
5228fn glob_import_ns_not_found() {
5229 check(
5230 indoc! {r#"
5231 namespace Main {
5232 import Bar.*;
5233 }
5234 "#},
5235 &expect![[r#"
5236 namespace namespace3 {
5237 import Bar.*;
5238 }
5239
5240 // GlobImportNamespaceNotFound("Bar", Span { lo: 28, hi: 31 })
5241 "#]],
5242 );
5243}
5244
5245#[test]
5246fn allow_export_of_namespace_within_itself() {
5247 check(
5248 indoc! {r#"
5249 namespace Foo {
5250 export Foo;
5251 }
5252 "#},
5253 &expect![[r#"
5254 namespace namespace3 {
5255 export namespace3;
5256 }
5257 "#]],
5258 );
5259}
5260
5261#[test]
5262fn export_of_item_with_same_name_as_namespace_resolves_to_item() {
5263 check(
5264 indoc! {r#"
5265 namespace Foo {
5266 operation Foo() : Unit {}
5267 export Foo;
5268 }
5269 "#},
5270 &expect![[r#"
5271 namespace namespace3 {
5272 operation item1() : Unit {}
5273 export item1;
5274 }
5275 "#]],
5276 );
5277}
5278
5279#[test]
5280fn export_of_item_with_same_name_as_namespace_resolves_to_item_even_when_before_item() {
5281 check(
5282 indoc! {r#"
5283 namespace Foo {
5284 export Foo;
5285 operation Foo() : Unit {}
5286 }
5287 "#},
5288 &expect![[r#"
5289 namespace namespace3 {
5290 export item1;
5291 operation item1() : Unit {}
5292 }
5293 "#]],
5294 );
5295}
5296
5297#[test]
5298fn ty_param_name_is_in_scope() {
5299 check(
5300 indoc! {r#"
5301 namespace Foo {
5302 operation Foo<'T: Eq>(a: 'T) : Unit {
5303 let x: 'T = a;
5304 }
5305 }
5306 "#},
5307 &expect![[r#"
5308 namespace namespace3 {
5309 operation item1<param0: Eq>(local10: param0) : Unit {
5310 let local19: param0 = local10;
5311 }
5312 }
5313 "#]],
5314 );
5315}
5316