Skip to content

Commit

Permalink
Continued working on new type resolution system and got simple local …
Browse files Browse the repository at this point in the history
…types resolving
  • Loading branch information
IsaacShelton committed Oct 12, 2024
1 parent 4ec6cc7 commit 2b0d268
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 289 deletions.
13 changes: 7 additions & 6 deletions src/resolve/expr/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
resolve::{
conform::{conform_expr, to_default::conform_expr_to_default, ConformMode, Perform},
error::{ResolveError, ResolveErrorKind},
resolve_type, Initialized,
Initialized, ResolveTypeCtx,
},
resolved::{self, TypedExpr},
source_files::Source,
Expand Down Expand Up @@ -91,12 +91,13 @@ pub fn resolve_call_expr(
}

if let Some(required_ty) = &call.expected_to_return {
let resolved_required_ty = resolve_type(
ctx.resolved_ast,
let type_ctx = ResolveTypeCtx::new(
&ctx.resolved_ast,
ctx.module_fs_node_id,
required_ty,
&mut Default::default(),
)?;
ctx.types_in_modules,
);

let resolved_required_ty = type_ctx.resolve(required_ty)?;

if resolved_required_ty != return_type {
return Err(ResolveErrorKind::FunctionMustReturnType {
Expand Down
25 changes: 13 additions & 12 deletions src/resolve/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::{
function_search_ctx::FunctionSearchCtx,
global_search_ctx::GlobalSearchCtx,
variable_search_ctx::VariableSearchCtx,
Initialized,
Initialized, ResolveTypeCtx,
};
use crate::{
ast::{
Expand All @@ -37,7 +37,7 @@ use crate::{
struct_literal::resolve_struct_literal_expr,
unary_operation::resolve_unary_math_operation_expr, variable::resolve_variable_expr,
},
resolve_stmts, resolve_type,
resolve_stmts,
},
resolved::{self, Expr, ExprKind, FunctionRef, StructureRef, TypeKind, TypedExpr},
workspace::fs::FsNodeId,
Expand All @@ -57,6 +57,7 @@ pub struct ResolveExprCtx<'a, 'b> {
pub helper_exprs: &'b IndexMap<ResolvedName, &'a ast::HelperExpr>,
pub settings: &'b Settings,
pub public_functions: &'b HashMap<FsNodeId, HashMap<String, Vec<resolved::FunctionRef>>>,
pub types_in_modules: &'b HashMap<FsNodeId, HashMap<String, resolved::TypeDecl>>,
pub module_fs_node_id: FsNodeId,
}

Expand Down Expand Up @@ -390,22 +391,22 @@ pub fn resolve_expr(
result_type,
} = &**info;

let resolved_type = resolve_type(
ctx.resolved_ast,
let resolved_type = ResolveTypeCtx::new(
&ctx.resolved_ast,
ctx.module_fs_node_id,
result_type,
&mut Default::default(),
)?;
ctx.types_in_modules,
)
.resolve(result_type)?;

let mut resolved_args = Vec::with_capacity(args.len());

for (expected_arg_type, arg) in args {
let preferred_type = resolve_type(
ctx.resolved_ast,
let type_ctx = ResolveTypeCtx::new(
&ctx.resolved_ast,
ctx.module_fs_node_id,
expected_arg_type,
&mut Default::default(),
)?;
ctx.types_in_modules,
);
let preferred_type = type_ctx.resolve(expected_arg_type)?;

resolved_args.push(
resolve_expr(
Expand Down
2 changes: 1 addition & 1 deletion src/resolve/global_search_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};
use std::collections::HashMap;

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct GlobalSearchCtx {
globals: HashMap<ResolvedName, (resolved::Type, GlobalVarRef)>,
}
Expand Down
Loading

0 comments on commit 2b0d268

Please sign in to comment.