[fine] Use the right tree to get the environment for an identifier
Can't go up to the parent, that defeats the whole point! Use *my* environment, not my parent's environment!!
This commit is contained in:
parent
2f71946d21
commit
4bd3ac06fa
2 changed files with 16 additions and 10 deletions
|
|
@ -351,8 +351,11 @@ impl<'a> Semantics<'a> {
|
||||||
Incremental::None => (),
|
Incremental::None => (),
|
||||||
Incremental::Complete(e) => return e.clone(),
|
Incremental::Complete(e) => return e.clone(),
|
||||||
Incremental::InProgress => {
|
Incremental::InProgress => {
|
||||||
// eprintln!("environment_of circular => {t:?}");
|
// NOTE: Set the state so the ICE doesn't loop on itself.
|
||||||
|
*state = Incremental::Complete(self.empty_environment.clone());
|
||||||
drop(borrow);
|
drop(borrow);
|
||||||
|
|
||||||
|
//eprintln!("environment_of circular => {t:?}");
|
||||||
self.internal_compiler_error(Some(t), "circular environment dependency");
|
self.internal_compiler_error(Some(t), "circular environment dependency");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -360,7 +363,7 @@ impl<'a> Semantics<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let tree = &self.syntax_tree[t];
|
let tree = &self.syntax_tree[t];
|
||||||
// eprintln!("environment_of => {tree:?}");
|
//eprintln!(">>> environment_of => {tree:?}");
|
||||||
|
|
||||||
let parent = match self.logical_parents[t.index()] {
|
let parent = match self.logical_parents[t.index()] {
|
||||||
Some(t) => self.environment_of(t),
|
Some(t) => self.environment_of(t),
|
||||||
|
|
@ -376,6 +379,7 @@ impl<'a> Semantics<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.environments.borrow_mut()[t.index()] = Incremental::Complete(result.clone());
|
self.environments.borrow_mut()[t.index()] = Incremental::Complete(result.clone());
|
||||||
|
//eprintln!("<<< environment_of => {tree:?}");
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -475,7 +479,7 @@ impl<'a> Semantics<'a> {
|
||||||
TreeKind::LetStatement => Some(Type::Nothing),
|
TreeKind::LetStatement => Some(Type::Nothing),
|
||||||
TreeKind::ReturnStatement => Some(Type::Unreachable),
|
TreeKind::ReturnStatement => Some(Type::Unreachable),
|
||||||
TreeKind::ExpressionStatement => self.type_of_expression_statement(tree),
|
TreeKind::ExpressionStatement => self.type_of_expression_statement(tree),
|
||||||
TreeKind::Identifier => self.type_of_identifier(tree),
|
TreeKind::Identifier => self.type_of_identifier(t, tree),
|
||||||
|
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
@ -743,16 +747,14 @@ impl<'a> Semantics<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_of_identifier(&self, tree: &Tree) -> Option<Type> {
|
fn type_of_identifier(&self, t: TreeRef, tree: &Tree) -> Option<Type> {
|
||||||
assert_eq!(tree.kind, TreeKind::Identifier);
|
assert_eq!(tree.kind, TreeKind::Identifier);
|
||||||
|
|
||||||
let id = tree.nth_token(0)?;
|
let id = tree.nth_token(0)?;
|
||||||
if let Some(parent) = tree.parent {
|
let environment = self.environment_of(t);
|
||||||
let environment = self.environment_of(parent);
|
|
||||||
if let Some(declaration) = environment.bind(id) {
|
if let Some(declaration) = environment.bind(id) {
|
||||||
return Some(declaration.declaration_type);
|
return Some(declaration.declaration_type);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.report_error_tree(tree, format!("cannot find value {id} here"));
|
self.report_error_tree(tree, format!("cannot find value {id} here"));
|
||||||
Some(Type::Error)
|
Some(Type::Error)
|
||||||
|
|
@ -801,7 +803,7 @@ impl<'a> Semantics<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_compiler_error(&self, tr: Option<TreeRef>, message: &str) -> ! {
|
fn internal_compiler_error(&self, tr: Option<TreeRef>, message: &str) -> ! {
|
||||||
eprintln!("Internan compiler error: {message}!");
|
eprintln!("Internal compiler error: {message}!");
|
||||||
self.dump_compiler_state(tr);
|
self.dump_compiler_state(tr);
|
||||||
panic!("INTERNAL COMPILER ERROR: {message}")
|
panic!("INTERNAL COMPILER ERROR: {message}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
fine/tests/expression/errors/unknown_variable.fine
Normal file
4
fine/tests/expression/errors/unknown_variable.fine
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
let x = y;
|
||||||
|
x;
|
||||||
|
|
||||||
|
// @type-error: 11 cannot find value y here
|
||||||
Loading…
Add table
Add a link
Reference in a new issue