[fine] No methods assigned to variables!

This commit is contained in:
John Doty 2024-01-24 09:11:55 -08:00
parent 0c69758b11
commit bc57978dda
2 changed files with 22 additions and 1 deletions

View file

@ -708,7 +708,17 @@ impl<'a> Semantics<'a> {
None => Type::Error,
};
// TODO: Variables cannot be of type <method>?
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,

View file

@ -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