diff --git a/fine/src/semantics.rs b/fine/src/semantics.rs index 57a74823..455ab09d 100644 --- a/fine/src/semantics.rs +++ b/fine/src/semantics.rs @@ -79,8 +79,6 @@ pub enum Type { String, Bool, - TypeArgument(TreeRef, Box), // An un-bound type argument - Function(Vec>, Box), } @@ -105,19 +103,9 @@ impl Type { (Type::Error, _) => true, (_, Type::Error) => true, - (Type::TypeArgument(a_id, ..), Type::TypeArgument(b_id, ..)) => a_id == b_id, - (_, _) => false, } } - - pub fn is_generic(&self) -> bool { - match self { - Type::TypeArgument(..) => true, - Type::Function(a, b) => a.iter().any(|t| t.is_generic()) || b.is_generic(), - _ => false, - } - } } impl fmt::Debug for Type { @@ -137,7 +125,6 @@ impl fmt::Display for Type { String => write!(f, "string"), Bool => write!(f, "bool"), MagicPrintGarbage => write!(f, "MagicPrintGarbage"), - TypeArgument(_, id) => write!(f, "{id}"), Function(args, ret) => { write!(f, "fun (")?; let mut first = true; @@ -666,7 +653,7 @@ impl<'a> Semantics<'a> { TreeKind::FunctionDecl => self.type_of_function_decl(tree), TreeKind::ReturnType => self.type_of_return_type(tree), - TreeKind::Parameter => self.type_of_parameter(t, tree), + TreeKind::Parameter => self.type_of_parameter(tree), _ => self.internal_compiler_error(Some(t), "asking for a nonsense type"), }; @@ -1027,14 +1014,13 @@ impl<'a> Semantics<'a> { Some(Type::Function(parameter_types, return_type)) } - fn type_of_parameter(&self, t: TreeRef, tree: &Tree) -> Option { + fn type_of_parameter(&self, tree: &Tree) -> Option { assert_eq!(tree.kind, TreeKind::Parameter); match tree.child_of_kind(self.syntax_tree, TreeKind::TypeExpression) { Some(t) => Some(self.type_of(t)), None => { - // It must be a generic parameter! We'll name this one after the tree where it exists. - let name = tree.nth_token(0)?; - Some(Type::TypeArgument(t, format!("${}", name.as_str()).into())) + self.report_error_tree(tree, format!("the parameter is missing a type")); + Some(Type::Error) } } } @@ -1126,7 +1112,7 @@ pub fn check(s: &Semantics) { TreeKind::File => {} TreeKind::FunctionDecl => check_function_decl(s, t, tree), TreeKind::ParamList => {} - TreeKind::Parameter => {} + TreeKind::Parameter => check_parameter(s, t), TreeKind::TypeExpression => { let _ = s.type_of_type_expr(tree); } @@ -1234,6 +1220,10 @@ fn check_return_statement(s: &Semantics, tree: &Tree) { // OK this one is a little bit messed up because it reaches *up*, sorry. } +fn check_parameter(s: &Semantics, t: TreeRef) { + let _ = s.type_of(t); +} + #[cfg(test)] mod tests { use super::*; diff --git a/fine/tests/expression/errors/missing_parameter.fine b/fine/tests/expression/errors/missing_parameter.fine new file mode 100644 index 00000000..9bd2ae3e --- /dev/null +++ b/fine/tests/expression/errors/missing_parameter.fine @@ -0,0 +1,5 @@ +fun this_is_missing_a_type(x) -> f64 { + 23 +} + +// @check-error: the parameter is missing a type \ No newline at end of file