Skip to content

Commit

Permalink
Typecheck projection by type
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Feb 5, 2020
1 parent 5e50ad9 commit 7ff5974
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
10 changes: 0 additions & 10 deletions dhall/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,6 @@ fn generate_tests() -> std::io::Result<()> {
false
// Too slow
|| path == "prelude"
// TODO: projection by expression
|| path == "unit/RecordProjectionByType"
|| path == "unit/RecordProjectionByTypeEmpty"
|| path == "unit/RecordProjectionByTypeJudgmentalEquality"
// TODO: record completion
|| path == "simple/completion"
|| path == "unit/Completion"
Expand All @@ -326,9 +322,6 @@ fn generate_tests() -> std::io::Result<()> {
variant: "TypeInferenceFailure",
path_filter: Box::new(|path: &str| {
false
// TODO: projection by expression
|| path == "unit/RecordProjectionByTypeFieldTypeMismatch"
|| path == "unit/RecordProjectionByTypeNotPresent"
// TODO: record completion
|| path == "unit/CompletionMissingRequiredField"
|| path == "unit/CompletionWithWrongDefaultType"
Expand All @@ -346,9 +339,6 @@ fn generate_tests() -> std::io::Result<()> {
variant: "TypeError",
path_filter: Box::new(|path: &str| {
false
// TODO: projection by expression
|| path == "unit/RecordProjectionByTypeFieldTypeMismatch"
|| path == "unit/RecordProjectionByTypeNotPresent"
// TODO: record completion
|| path == "unit/CompletionMissingRequiredField"
|| path == "unit/CompletionWithWrongDefaultType"
Expand Down
27 changes: 25 additions & 2 deletions dhall/src/semantics/tck/typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,31 @@ fn type_one_layer(
record_type.get_type()?,
)
}
ExprKind::ProjectionByExpr(_, _) => {
unimplemented!("selection by expression")
ExprKind::ProjectionByExpr(record, selection) => {
let record_type = record.get_type()?;
let rec_kts = match record_type.kind() {
ValueKind::RecordType(kts) => kts,
_ => return span_err("ProjectionMustBeRecord"),
};

let selection_val = selection.eval(env.as_nzenv());
let sel_kts = match selection_val.kind() {
ValueKind::RecordType(kts) => kts,
_ => return span_err("ProjectionByExprTakesRecordType"),
};

for (l, sel_ty) in sel_kts {
match rec_kts.get(l) {
Some(rec_ty) => {
if rec_ty != sel_ty {
return span_err("ProjectionWrongType");
}
}
None => return span_err("ProjectionMissingEntry"),
}
}

selection_val
}
ExprKind::Completion(_, _) => unimplemented!("record completion"),
})
Expand Down

0 comments on commit 7ff5974

Please sign in to comment.