Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Sep 12, 2024
1 parent 0eda370 commit e9162bf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: cli/tests/snapshot/main.rs
expression: err
---
error: pattern binding failed
error: destructuring failed
┌─ [INPUTS_PATH]/errors/destructuring_closed_fail.ncl:3:5
3let {a} = {a=1, b=2}
Expand Down
2 changes: 1 addition & 1 deletion core/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ impl IntoDiagnostics<FileId> for EvalError {
.push(secondary_term(&value, files).with_message("this value failed to match"));

vec![Diagnostic::error()
.with_message("pattern binding failed")
.with_message("destructuring failed")
.with_labels(labels)]
}
EvalError::IllegalPolymorphicTailAccess {
Expand Down
10 changes: 6 additions & 4 deletions core/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,10 @@ where
Lbl(_lbl) => allocator.text("%<label>").append(allocator.line()),
Let(bindings, body, attrs) => docs![
allocator,
"let ",
"let",
allocator.space(),
if attrs.rec {
allocator.text("rec ")
docs![allocator, "rec", allocator.space()]
} else {
allocator.nil()
},
Expand All @@ -885,9 +886,10 @@ where
.group(),
LetPattern(bindings, body, attrs) => docs![
allocator,
"let ",
"let",
allocator.space(),
if attrs.rec {
allocator.text("rec ")
docs![allocator, "rec", allocator.space()]
} else {
allocator.nil()
},
Expand Down
6 changes: 1 addition & 5 deletions core/src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2762,14 +2762,10 @@ pub mod make {
T2: Into<RichTerm>,
D: Into<Pattern>,
{
let attrs = LetAttrs {
binding_type: BindingType::Normal,
rec: false,
};
Term::LetPattern(
std::iter::once((pat.into(), t1.into())).collect(),
t2.into(),
attrs,
LetAttrs::default(),
)
.into()
}
Expand Down
10 changes: 3 additions & 7 deletions core/src/transform/desugar_destructuring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ pub fn transform_one(rt: RichTerm) -> RichTerm {
pub fn desugar_fun(mut pat: Pattern, body: RichTerm) -> Term {
let id = pat.alias.take().unwrap_or_else(LocIdent::fresh);
let pos_body = body.pos;
let attrs = LetAttrs {
binding_type: BindingType::Normal,
rec: false,
};

Term::Fun(
id,
RichTerm::new(
Term::LetPattern(
std::iter::once((pat, Term::Var(id).into())).collect(),
body,
attrs,
LetAttrs::default(),
),
// TODO: should we use rt.pos?
pos_body,
Expand Down Expand Up @@ -87,8 +83,8 @@ pub fn desugar_fun(mut pat: Pattern, body: RichTerm) -> Term {
///
/// There's some ambiguity about where to put the error-checking. It might be natural
/// to put it before trying to access `%r1.foo`, but that would only raise the error
/// if someone tries to evaluate `foo`. The place we've put it above puts the error
/// check raises an error, for example, in `let 'Foo = 'Bar in true`.
/// if someone tries to evaluate `foo`. Putting it in the body as above raises
/// an error, for example, in `let 'Foo = 'Bar in true`.
///
/// A recursive let-binding is desugared almost the same way, except that everything is
/// shoved into a single let-rec block instead of three nested blocks.
Expand Down
2 changes: 1 addition & 1 deletion doc/manual/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ Examples:
[ 2, 3 ]
> let 'Invalid x = {} in x
error: pattern binding failed
error: destructuring failed
[...]
```

Expand Down

0 comments on commit e9162bf

Please sign in to comment.