1
1
mirror of https://github.com/tweag/nickel.git synced 2024-10-04 23:27:15 +03:00

Fix field without definition assigned null value

Fixes #697
This commit is contained in:
Steven Shaw 2022-05-20 16:18:07 +10:00
parent e87e7f438e
commit 7a4d3b5dcf
No known key found for this signature in database
GPG Key ID: 1D9A17DFD23DCB91
2 changed files with 17 additions and 1 deletions

View File

@ -337,7 +337,7 @@ RecordField: (FieldPath, RichTerm) = {
if let Some(deft) = t {
deft
} else {
RichTerm::new(Term::Null, pos)
RichTerm::new(Term::MetaValue(MetaValue::new()), pos)
}
};

View File

@ -49,3 +49,19 @@ fn dynamic_not_recursive() {
Err(Error::TypecheckError(TypecheckError::UnboundIdentifier(..)))
);
}
#[test]
fn missing_field() {
assert_matches!(
eval("{foo | Num, bar = foo + 1}.foo"),
Err(Error::EvalError(EvalError::MissingFieldDef(..)))
);
assert_matches!(
eval("{foo : Num, bar = foo + 1}.foo"),
Err(Error::EvalError(EvalError::MissingFieldDef(..)))
);
assert_matches!(
eval("{foo, bar = foo + 1}.foo"),
Err(Error::EvalError(EvalError::MissingFieldDef(..)))
)
}