File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed
source/compiler/qsc_passes/src Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ namespace Kata.Verification {
1313 for _ in 1 .. 10 {
1414 use qs = Qubit [n ];
1515 let theta = DrawRandomDouble (0.0 , 1.0 );
16- within {
16+ let correct = within {
1717 // Prepare logical state on first qubit
1818 Ry (2.0 * theta * PI (), qs [0 ]);
1919 // Encode the state in multiple qubits
@@ -30,9 +30,14 @@ namespace Kata.Verification {
3030 Message ("Incorrect." );
3131 let actual = err_ind == - 1 ? "No error happened" | $"Error happened on qubit {err_ind}" ;
3232 Message ($"{actual}, but solution returned {detected}" );
33- ResetAll (qs );
34- return false ;
33+ false
34+ } else {
35+ true
3536 }
37+ };
38+ if not correct {
39+ ResetAll (qs );
40+ return false ;
3641 }
3742 // Check that the state was not modified by the solution
3843 if not CheckAllZero (qs ) {
Original file line number Diff line number Diff line change @@ -241,6 +241,8 @@ impl<'a> Visitor<'a> for ReturnCheck {
241241 fn visit_expr ( & mut self , expr : & ' a Expr ) {
242242 if matches ! ( & expr. kind, ExprKind :: Return ( ..) ) {
243243 self . errors . push ( Error :: ReturnForbidden ( expr. span ) ) ;
244+ } else {
245+ visit:: walk_expr ( self , expr) ;
244246 }
245247 }
246248}
Original file line number Diff line number Diff line change @@ -537,6 +537,39 @@ fn conjugate_return_in_apply_fail() {
537537 ) ;
538538}
539539
540+ #[ test]
541+ fn conjugate_return_nested_in_apply_fail ( ) {
542+ check (
543+ indoc ! { "
544+ namespace Test {
545+ operation B(i : Int) : Unit is Adj {}
546+ operation A() : Unit {
547+ mutable a = 1;
548+ within {
549+ let x = a;
550+ B(2);
551+ }
552+ apply {
553+ if true {
554+ return ();
555+ }
556+ }
557+ }
558+ }
559+ " } ,
560+ & expect ! [ [ r#"
561+ [
562+ ReturnForbidden(
563+ Span {
564+ lo: 231,
565+ hi: 240,
566+ },
567+ ),
568+ ]
569+ "# ] ] ,
570+ ) ;
571+ }
572+
540573#[ test]
541574fn conjugate_mutable_correct_use_succeeds ( ) {
542575 check (
You can’t perform that action at this time.
0 commit comments