Skip to content

Commit 9c33427

Browse files
authored
Panic in Language Service: unexpected expr type in assignment (#2833)
Fixes #2832
1 parent e71b3f4 commit 9c33427

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

source/compiler/qsc_passes/src/conjugate_invert.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ impl<'a> Visitor<'a> for AssignmentCheck {
216216
impl AssignmentCheck {
217217
fn check_assign(&mut self, expr: &Expr) {
218218
match &expr.kind {
219-
ExprKind::Hole => {}
220219
ExprKind::Var(Res::Local(id), _) => {
221220
if self.used.contains(id) {
222221
self.errors.push(Error::ApplyAssign(expr.span));
@@ -227,7 +226,9 @@ impl AssignmentCheck {
227226
self.check_assign(expr);
228227
}
229228
}
230-
_ => panic!("unexpected expr type in assignment"),
229+
// Other LHS kinds are not assignable, which is a semantic error
230+
// handled by the borrow checker pass.
231+
_ => {}
231232
}
232233
}
233234
}

source/compiler/qsc_passes/src/conjugate_invert/tests.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,80 @@ fn conjugate_mutable_update_in_apply_fail() {
432432
);
433433
}
434434

435+
#[test]
436+
fn conjugate_allowed_mutable_with_invalid_lhs_ignored() {
437+
check(
438+
indoc! {"
439+
namespace Test {
440+
operation B(i : Int) : Unit is Adj {}
441+
operation A() : Unit {
442+
mutable a = 1;
443+
within {
444+
B(1);
445+
}
446+
apply {
447+
set (a + 1) = 3;
448+
B(2);
449+
}
450+
}
451+
}
452+
"},
453+
&expect![[r#"
454+
Package:
455+
Item 0 [0-234] (Public):
456+
Namespace (Ident 33 [10-14] "Test"): Item 1, Item 2
457+
Item 1 [21-58] (Internal):
458+
Parent: 0
459+
Callable 0 [21-58] (operation):
460+
name: Ident 1 [31-32] "B"
461+
input: Pat 2 [33-40] [Type Int]: Bind: Ident 3 [33-34] "i"
462+
output: Unit
463+
functors: Adj
464+
body: SpecDecl 4 [21-58]: Impl:
465+
Block 5 [56-58]: <empty>
466+
adj: <none>
467+
ctl: <none>
468+
ctl-adj: <none>
469+
Item 2 [63-232] (Internal):
470+
Parent: 0
471+
Callable 6 [63-232] (operation):
472+
name: Ident 7 [73-74] "A"
473+
input: Pat 8 [74-76] [Type Unit]: Unit
474+
output: Unit
475+
functors: empty set
476+
body: SpecDecl 9 [63-232]: Impl:
477+
Block 10 [84-232] [Type Unit]:
478+
Stmt 11 [94-108]: Local (Mutable):
479+
Pat 12 [102-103] [Type Int]: Bind: Ident 13 [102-103] "a"
480+
Expr 14 [106-107] [Type Int]: Lit: Int(1)
481+
Stmt 15 [117-226]: Expr: Expr 51 [0-0] [Type Unit]: Expr Block: Block 44 [0-0] [Type Unit]:
482+
Stmt 45 [0-0]: Expr: Expr 46 [0-0] [Type Unit]: Expr Block: Block 17 [124-153] [Type Unit]:
483+
Stmt 18 [138-143]: Semi: Expr 19 [138-142] [Type Unit]: Call:
484+
Expr 20 [138-139] [Type (Int => Unit is Adj)]: Var: Item 1 (Package 1)
485+
Expr 21 [140-141] [Type Int]: Lit: Int(1)
486+
Stmt 41 [0-0]: Local (Immutable):
487+
Pat 42 [0-0] [Type Unit]: Bind: Ident 40 [0-0] "@apply_res"
488+
Expr 43 [0-0] [Type Unit]: Expr Block: Block 22 [168-226] [Type Unit]:
489+
Stmt 23 [182-198]: Semi: Expr 24 [182-197] [Type Unit]: Assign:
490+
Expr 25 [187-192] [Type Int]: BinOp (Add):
491+
Expr 26 [187-188] [Type Int]: Var: Local 13
492+
Expr 27 [191-192] [Type Int]: Lit: Int(1)
493+
Expr 28 [196-197] [Type Int]: Lit: Int(3)
494+
Stmt 29 [211-216]: Semi: Expr 30 [211-215] [Type Unit]: Call:
495+
Expr 31 [211-212] [Type (Int => Unit is Adj)]: Var: Item 1 (Package 1)
496+
Expr 32 [213-214] [Type Int]: Lit: Int(2)
497+
Stmt 47 [0-0]: Expr: Expr 48 [0-0] [Type Unit]: Expr Block: Block 34 [124-153] [Type Unit]:
498+
Stmt 35 [138-143]: Semi: Expr 36 [138-142] [Type Unit]: Call:
499+
Expr 37 [138-139] [Type (Int => Unit is Adj)]: UnOp (Functor Adj):
500+
Expr 38 [138-139] [Type (Int => Unit is Adj)]: Var: Item 1 (Package 1)
501+
Expr 39 [140-141] [Type Int]: Lit: Int(1)
502+
Stmt 49 [0-0]: Expr: Expr 50 [0-0] [Type Unit]: Var: Local 40
503+
adj: <none>
504+
ctl: <none>
505+
ctl-adj: <none>"#]],
506+
);
507+
}
508+
435509
#[test]
436510
fn conjugate_return_in_apply_fail() {
437511
check(

0 commit comments

Comments
 (0)