Merge pull request #3090 from rtfeldman/expr-blank

This commit is contained in:
Richard Feldman 2022-05-18 21:25:07 -04:00 committed by GitHub
commit 0f3709da6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 3 deletions

View file

@ -204,10 +204,13 @@ pub enum Expr {
lambda_set_variables: Vec<LambdaSet>, lambda_set_variables: Vec<LambdaSet>,
}, },
// Test /// Test
Expect(Box<Loc<Expr>>, Box<Loc<Expr>>), Expect(Box<Loc<Expr>>, Box<Loc<Expr>>),
// Compiles, but will crash if reached /// Rendered as empty box in editor
TypedHole(Variable),
/// Compiles, but will crash if reached
RuntimeError(RuntimeError), RuntimeError(RuntimeError),
} }
@ -247,7 +250,9 @@ impl Expr {
}, },
&Self::OpaqueRef { name, .. } => Category::OpaqueWrap(name), &Self::OpaqueRef { name, .. } => Category::OpaqueWrap(name),
Self::Expect(..) => Category::Expect, Self::Expect(..) => Category::Expect,
Self::RuntimeError(..) => Category::Unknown,
// these nodes place no constraints on the expression's type
Self::TypedHole(_) | Self::RuntimeError(..) => Category::Unknown,
} }
} }
} }
@ -1391,6 +1396,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
| other @ Var(_) | other @ Var(_)
| other @ AbilityMember(..) | other @ AbilityMember(..)
| other @ RunLowLevel { .. } | other @ RunLowLevel { .. }
| other @ TypedHole { .. }
| other @ ForeignCall { .. } => other, | other @ ForeignCall { .. } => other,
List { List {

View file

@ -710,6 +710,7 @@ fn fix_values_captured_in_closure_expr(
| Var(_) | Var(_)
| AbilityMember(..) | AbilityMember(..)
| EmptyRecord | EmptyRecord
| TypedHole { .. }
| RuntimeError(_) | RuntimeError(_)
| ZeroArgumentTag { .. } | ZeroArgumentTag { .. }
| Accessor { .. } => {} | Accessor { .. } => {}

View file

@ -168,6 +168,7 @@ pub fn walk_expr<V: Visitor>(visitor: &mut V, expr: &Expr, var: Variable) {
visitor.visit_expr(&e1.value, e1.region, Variable::NULL); visitor.visit_expr(&e1.value, e1.region, Variable::NULL);
visitor.visit_expr(&e2.value, e2.region, Variable::NULL); visitor.visit_expr(&e2.value, e2.region, Variable::NULL);
} }
Expr::TypedHole(_) => { /* terminal */ }
Expr::RuntimeError(..) => { /* terminal */ } Expr::RuntimeError(..) => { /* terminal */ }
} }
} }

View file

@ -1144,6 +1144,15 @@ pub fn constrain_expr(
arg_cons.push(eq); arg_cons.push(eq);
constraints.exists_many(vars, arg_cons) constraints.exists_many(vars, arg_cons)
} }
TypedHole(var) => {
// store the expected type for this position
constraints.equal_types_var(
*var,
expected,
Category::Storage(std::file!(), std::line!()),
region,
)
}
RuntimeError(_) => { RuntimeError(_) => {
// Runtime Errors have no constraints because they're going to crash. // Runtime Errors have no constraints because they're going to crash.
Constraint::True Constraint::True

View file

@ -366,6 +366,8 @@ pub fn deep_copy_type_vars_into_expr<'a>(
Expect(e1, e2) => Expect(Box::new(e1.map(go_help)), Box::new(e2.map(go_help))), Expect(e1, e2) => Expect(Box::new(e1.map(go_help)), Box::new(e2.map(go_help))),
TypedHole(v) => TypedHole(sub!(*v)),
RuntimeError(err) => RuntimeError(err.clone()), RuntimeError(err) => RuntimeError(err.clone()),
} }
} }

View file

@ -5229,6 +5229,7 @@ pub fn with_hole<'a>(
} }
} }
} }
TypedHole(_) => Stmt::RuntimeError("Hit a blank"),
RuntimeError(e) => Stmt::RuntimeError(env.arena.alloc(format!("{:?}", e))), RuntimeError(e) => Stmt::RuntimeError(env.arena.alloc(format!("{:?}", e))),
} }
} }