diff --git a/src/check.rs b/src/check.rs index 42d2522d63039123c71891d0723cf5a2a94fe44f..46c2d2a53031e18148408a3bdef1c4a6eb9c6486 100644 --- a/src/check.rs +++ b/src/check.rs @@ -194,6 +194,16 @@ fn strip_mut(t: Type) -> Type { } } +fn is_known(t: &Type) -> bool { + use Type::*; + match t { + Type::Unknown => false, + Unit | Bool | I32 => true, + Mut(t) | Ref(t) => is_known(t), + _ => panic!("ICE is_known"), + } +} + pub fn check_stmts( stmts: &Stmts, fn_env: &FnEnv, @@ -223,7 +233,13 @@ pub fn check_stmts( } } } - (None, Some(e)) => expr_type(&*e, fn_env, type_env, var_env)?, + (None, Some(e)) => { + let et = expr_type(&*e, fn_env, type_env, var_env)?; + match is_known(&et) { + true => et, + _ => Err("reference to unknown type".to_string())?, + } + } (Some(t), None) => t.clone(), _ => Type::Unknown, };