-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incomplete check of row constraints
In an attempt to free the allocation of the constraints of a record row unification variable that is being assigned to some record rows, the code checking that row constraints are satisfied was removing the constraints from the global state. Since rows are defined as linked list, if the constraint wasn't violated on the first row, this function would recursively call itself. But then the subsequent recursive calls would try to get the constraints from the state again, to only find an empty set constraints, as it has been removed just before. The function thus wouldn't detect constraint violations happening in the tail of the record rows. This patch defines a subfunction which passes the initial constraints along recursive calls, such that they aren't lost during recursion, instead of trying to get them from the state again at each recursive call.
- Loading branch information
Showing
4 changed files
with
84 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
core/tests/integration/typecheck/fail/row_conflict_poly_shuffled1.ncl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# test.type = 'error' | ||
# eval = 'typecheck' | ||
# | ||
# [test.metadata] | ||
# error = 'TypecheckError::RowConflict' | ||
# | ||
# [test.metadata.expectation] | ||
# row = 'a' | ||
|
||
# Regression test for issue #1393 (https://github.com/tweag/nickel/issues/1393). | ||
# Ensure that row constraints are properly checked, indepedently of the order of | ||
# row declarations. | ||
let f | ||
| forall r. {; r } -> { a : Number, b : Number; r } | ||
# the implementation doesn't matter, we care about types | ||
= fun r => null | ||
in | ||
let g = fun x => 'a in | ||
g ((f { a = 0, x = 0, y = 0 }) : _) | ||
|
20 changes: 20 additions & 0 deletions
20
core/tests/integration/typecheck/fail/row_conflict_poly_shuffled2.ncl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# test.type = 'error' | ||
# eval = 'typecheck' | ||
# | ||
# [test.metadata] | ||
# error = 'TypecheckError::RowConflict' | ||
# | ||
# [test.metadata.expectation] | ||
# row = 'a' | ||
|
||
# Regression test for issue #1393 (https://github.com/tweag/nickel/issues/1393). | ||
# Ensure that row constraints are properly checked, indepedently of the order of | ||
# row declarations. | ||
let f | ||
| forall r. {; r } -> { a : Number, b : Number; r } | ||
# the implementation doesn't matter, we care about types | ||
= fun r => null | ||
in | ||
let g = fun x => 'a in | ||
g ((f { x = 0, a = 0, y = 0 }) : _) | ||
|
20 changes: 20 additions & 0 deletions
20
core/tests/integration/typecheck/fail/row_conflict_poly_shuffled3.ncl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# test.type = 'error' | ||
# eval = 'typecheck' | ||
# | ||
# [test.metadata] | ||
# error = 'TypecheckError::RowConflict' | ||
# | ||
# [test.metadata.expectation] | ||
# row = 'a' | ||
|
||
# Regression test for issue #1393 (https://github.com/tweag/nickel/issues/1393). | ||
# Ensure that row constraints are properly checked, indepedently of the order of | ||
# row declarations. | ||
let f | ||
| forall r. {; r } -> { a : Number, b : Number; r } | ||
# the implementation doesn't matter, we care about types | ||
= fun r => null | ||
in | ||
let g = fun x => 'a in | ||
g ((f { x = 0, y = 0, a = 0 }) : _) | ||
|