implement type inference for literals

This commit is contained in:
NotAFile 2022-02-23 22:02:45 +01:00
parent f03c777e28
commit 8c16a94be4
2 changed files with 7 additions and 3 deletions

View File

@ -292,7 +292,7 @@ impl Context {
return expr.clone();
}
match &expr.kind {
typed_ir::ExprKind::Literal(_) => todo!(),
typed_ir::ExprKind::Literal(lit) => expr.clone().with_type(lit.typ),
// we can not see beyond this expression right now
typed_ir::ExprKind::Path(_) => expr.clone(),
typed_ir::ExprKind::Call {
@ -372,7 +372,11 @@ impl Context {
expr: &typed_ir::Expr,
) -> std::fmt::Result {
let expr_pretty = match &expr.kind {
typed_ir::ExprKind::Literal(_) => todo!(),
typed_ir::ExprKind::Literal(lit) => {
let mut lit_str = String::new();
self.types.pretty_value(&mut lit_str, lit)?;
lit_str
}
typed_ir::ExprKind::Path(path) => format!("sig_{}", path.0),
typed_ir::ExprKind::Call {
called,

View File

@ -43,7 +43,7 @@ pub struct FnSig {
#[derive(Debug, Clone)]
pub struct ElabData {
typ: Type,
pub typ: Type,
value: ElabValue,
}