diff --git a/compiler/src/passes/parse/parse.rs b/compiler/src/passes/parse/parse.rs index ebad780..e2d5194 100644 --- a/compiler/src/passes/parse/parse.rs +++ b/compiler/src/passes/parse/parse.rs @@ -1,5 +1,5 @@ use crate::passes::parse::grammar::ProgramParser; -use crate::passes::parse::{Expr, PrgParsed}; +use crate::passes::parse::PrgParsed; use itertools::Itertools; use lalrpop_util::lexer::Token; use lalrpop_util::ParseError; diff --git a/compiler/src/passes/validate/type_check/mod.rs b/compiler/src/passes/validate/type_check/mod.rs index a1d1cfc..914f50a 100644 --- a/compiler/src/passes/validate/type_check/mod.rs +++ b/compiler/src/passes/validate/type_check/mod.rs @@ -78,7 +78,7 @@ impl<'p> PrgParsed<'p> { in_loop: false, return_type: &typ, }; - let bdy = validate_expr(bdy, &mut env)?; + let bdy = validate_expr(bdy.expr, &mut env)?; expect_type(&bdy, &typ)?; Ok(( sym, diff --git a/compiler/src/passes/validate/type_check/validate_expr.rs b/compiler/src/passes/validate/type_check/validate_expr.rs index 0b42b2c..19743c6 100644 --- a/compiler/src/passes/validate/type_check/validate_expr.rs +++ b/compiler/src/passes/validate/type_check/validate_expr.rs @@ -78,10 +78,10 @@ pub fn validate_expr<'p>( } } Expr::Apply { fun, args, .. } => { - let fun = validate_expr(*fun, env)?; + let fun = validate_expr(fun.expr, env)?; let args = args .into_iter() - .map(|arg| validate_expr(arg, env)) + .map(|arg| validate_expr(arg.expr, env)) .collect::, _>>()?; let Type::Fn { params, typ } = fun.typ() else { @@ -116,7 +116,7 @@ pub fn validate_expr<'p>( in_loop: true, return_type: env.return_type, }; - let bdy = validate_expr(*bdy, &mut env)?; + let bdy = validate_expr(bdy.expr, &mut env)?; TExpr::Loop { bdy: Box::new(bdy), typ: loop_type.unwrap_or(Type::Never), @@ -125,7 +125,7 @@ pub fn validate_expr<'p>( Expr::Break { bdy, .. } => { expect(env.in_loop, BreakOutsideLoop)?; - let bdy = validate_expr(*bdy, env)?; + let bdy = validate_expr(bdy.expr, env)?; if let Some(loop_type) = env.loop_type { expect_type(&bdy, loop_type)?; @@ -139,8 +139,8 @@ pub fn validate_expr<'p>( } } Expr::Seq { stmt, cnt, .. } => { - let stmt = validate_expr(*stmt, env)?; - let cnt = validate_expr(*cnt, env)?; + let stmt = validate_expr(stmt.expr, env)?; + let cnt = validate_expr(cnt.expr, env)?; TExpr::Seq { typ: cnt.typ().clone(), @@ -166,7 +166,7 @@ pub fn validate_expr<'p>( }, )?; - let bnd = validate_expr(*bnd, env)?; + let bnd = validate_expr(bnd.expr, env)?; TExpr::Assign { sym, bnd: Box::new(bnd), @@ -175,7 +175,7 @@ pub fn validate_expr<'p>( } Expr::Continue { .. } => TExpr::Continue { typ: Type::Never }, Expr::Return { bdy, .. } => { - let bdy = validate_expr(*bdy, env)?; + let bdy = validate_expr(bdy.expr, env)?; expect_type(&bdy, env.return_type)?; TExpr::Return { bdy: Box::new(bdy), @@ -184,7 +184,7 @@ pub fn validate_expr<'p>( } Expr::Struct { sym, fields, .. } => validate_struct(env, sym, fields)?, Expr::AccessField { strct, field, .. } => { - let strct = validate_expr(*strct, env)?; + let strct = validate_expr(strct.expr, env)?; let Type::Var { sym } = strct.typ() else { return Err(TypeShouldBeStruct { diff --git a/compiler/src/passes/validate/type_check/validate_prim.rs b/compiler/src/passes/validate/type_check/validate_prim.rs index 04357a2..16f3397 100644 --- a/compiler/src/passes/validate/type_check/validate_prim.rs +++ b/compiler/src/passes/validate/type_check/validate_prim.rs @@ -12,7 +12,7 @@ pub fn validate_prim<'p>( ) -> Result, TypeError> { let args = args .into_iter() - .map(|arg| validate_expr(arg.ex, env)) + .map(|arg| validate_expr(arg.expr, env)) .collect::, _>>()?; let typ = match &(op, args.as_slice()) { diff --git a/compiler/src/passes/validate/type_check/validate_struct.rs b/compiler/src/passes/validate/type_check/validate_struct.rs index 41f1a30..3981f2a 100644 --- a/compiler/src/passes/validate/type_check/validate_struct.rs +++ b/compiler/src/passes/validate/type_check/validate_struct.rs @@ -1,5 +1,5 @@ use crate::passes::parse::types::Type; -use crate::passes::parse::{Expr, TypeDef}; +use crate::passes::parse::{Expr, Spanned, TypeDef}; use crate::passes::validate::type_check::error::TypeError; use crate::passes::validate::type_check::error::TypeError::*; use crate::passes::validate::type_check::expect_type; @@ -12,7 +12,7 @@ use std::collections::{HashMap, HashSet}; pub fn validate_struct<'p>( env: &mut Env<'_, 'p>, sym: &'p str, - fields: Vec<(&'p str, Expr<'p>)>, + fields: Vec<(&'p str, Spanned>)>, ) -> Result, TypeError> { let entry = env.scope.get(&sym).ok_or(UndeclaredVar { sym: sym.to_string(), @@ -32,7 +32,7 @@ pub fn validate_struct<'p>( let fields = fields .into_iter() .map(|(field, expr)| { - let expr = validate_expr(expr, env)?; + let expr = validate_expr(expr.expr, env)?; expect( new_provided_fields.insert(field),