From bc57978dda23165e342311045c08195cea490307 Mon Sep 17 00:00:00 2001 From: John Doty Date: Wed, 24 Jan 2024 09:11:55 -0800 Subject: [PATCH] [fine] No methods assigned to variables! --- fine/src/semantics.rs | 12 +++++++++++- .../tests/expression/errors/no_method_variables.fine | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 fine/tests/expression/errors/no_method_variables.fine diff --git a/fine/src/semantics.rs b/fine/src/semantics.rs index 87f899e8..87c23214 100644 --- a/fine/src/semantics.rs +++ b/fine/src/semantics.rs @@ -708,7 +708,17 @@ impl<'a> Semantics<'a> { None => Type::Error, }; - // TODO: Variables cannot be of type ? + let declaration_type = match declaration_type { + Type::Method(..) => { + let start = name.start; + let end = name.start + name.as_str().len(); + self.report_error_span(start, end, "methods cannot be assigned to variables"); + Type::Error + } + _ => declaration_type, + }; + + eprintln!("{} => {}", name, declaration_type); let location = match parent.location { Location::Local => Location::Local, diff --git a/fine/tests/expression/errors/no_method_variables.fine b/fine/tests/expression/errors/no_method_variables.fine new file mode 100644 index 00000000..a2a85579 --- /dev/null +++ b/fine/tests/expression/errors/no_method_variables.fine @@ -0,0 +1,11 @@ +class Foo { + fun bar(self) {} +} + +fun test() { + let obj = new Foo {}; + let f = obj.bar; +} + +// @expect-errors: +// | 7:6: methods cannot be assigned to variables