Skip to content

Commit

Permalink
fixes ident update in cond expression (#140)
Browse files Browse the repository at this point in the history
initially the following expression would fail
```
let x = 1;
cond (a: 2) {
	(a: x): x
}
```

This is due to a scope check that is done during bindings. The check
has been removed to allow regular binding. The previous expression will
bind the value `2` to `x`.
  • Loading branch information
nofun97 authored Mar 23, 2021
1 parent 27dfb16 commit 9953e4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 1 addition & 4 deletions rel/expr_cond_pattern_control_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ func (e CondPatternControlVarExpr) Eval(ctx context.Context, scope Scope) (Value
ctx, bindings, err := conditionPair.Bind(ctx, scope, varVal)
// TODO: This will misbehave if there's a genuine error in pattern matching, err !=nil gets through as nil
if err == nil {
l, err := scope.MatchedUpdate(bindings)
if err != nil {
return nil, WrapContextErr(err, e.controlVarExpr, scope)
}
l := scope.Update(bindings)
val, err := conditionPair.eval(ctx, l)
if err != nil {
return nil, WrapContextErr(err, e.controlVarExpr, l)
Expand Down
3 changes: 3 additions & 0 deletions syntax/expr_cond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,7 @@ func TestEvalCondPatternMatchingWithControlVar(t *testing.T) { //nolint:dupl

AssertCodesEvalToSameValue(t, `1`, `let a = 2; cond (x: 2) {(x: (a)): 1, _: 2}`)
AssertCodesEvalToSameValue(t, `2`, `let a = 3; cond (x: 2) {(x: (a)): 1, _: 2}`)

AssertCodesEvalToSameValue(t, `2`, `let a = 1; cond (x: 2) {(x: a): a, _: false}`)
AssertCodesEvalToSameValue(t, `2`, `let a = 1; cond ({"x": 2}) {{"x": a}: a, _: false}`)
}

0 comments on commit 9953e4d

Please sign in to comment.