Skip to content

Commit

Permalink
Update forward refs test case result
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyphack committed Sep 10, 2024
1 parent 07d1a6d commit d341a32
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 89 deletions.
7 changes: 6 additions & 1 deletion typechecker/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use enderpy_python_parser::ast::{self, *};

use super::{type_evaluator::TypeEvaluator, types::PythonType};
use crate::symbol_table::Id;
use crate::type_evaluator::GetTypeFlags;
use crate::types::ModuleRef;
use crate::{ast_visitor::TraversalVisitor, diagnostic::CharacterSpan, symbol_table::SymbolTable};
use rust_lapper::{Interval, Lapper};
Expand Down Expand Up @@ -44,7 +45,10 @@ impl<'a> TypeChecker<'a> {
}

fn infer_expr_type(&mut self, expr: &Expression) -> PythonType {
let t = match self.type_evaluator.get_type(expr, None, None) {
let t = match self
.type_evaluator
.get_type(expr, None, None, GetTypeFlags::empty())
{
Ok(t) => t,
Err(e) => {
log::error!("type evaluator error: {} for expr {expr:?}", e);
Expand All @@ -68,6 +72,7 @@ impl<'a> TypeChecker<'a> {
None,
&self.type_evaluator.symbol_table,
Some(self.type_evaluator.symbol_table.current_scope_id),
GetTypeFlags::empty(),
)
.unwrap_or(PythonType::Unknown);
self.types.insert(Interval {
Expand Down
11 changes: 11 additions & 0 deletions typechecker/src/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,17 @@ impl SymbolTableNode {
.expect("There must be at least one declaration")
}

pub fn get_declaration_until_pos(&self, pos: u32) -> Option<&Declaration> {
// TODO: Handle iterating declarations from last to first
for declaration in self.declarations.iter() {
if declaration.declaration_path().node.start <= pos {
return Some(declaration);
}
}

None
}

pub fn declaration_until_position(&self, position: u32) -> Option<&Declaration> {
let mut filtered_declarations = self
.declarations
Expand Down
Loading

0 comments on commit d341a32

Please sign in to comment.