Skip to content

Commit

Permalink
Pass spans to type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanBrouwer committed Nov 7, 2023
1 parent a54c404 commit 152053a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion compiler/src/passes/parse/parse.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/passes/validate/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions compiler/src/passes/validate/type_check/validate_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<Vec<_>, _>>()?;

let Type::Fn { params, typ } = fun.typ() else {
Expand Down Expand Up @@ -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),
Expand All @@ -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)?;
Expand All @@ -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(),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/passes/validate/type_check/validate_prim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn validate_prim<'p>(
) -> Result<TExpr<'p, &'p str>, TypeError> {
let args = args
.into_iter()
.map(|arg| validate_expr(arg.ex, env))
.map(|arg| validate_expr(arg.expr, env))
.collect::<Result<Vec<_>, _>>()?;

let typ = match &(op, args.as_slice()) {
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/passes/validate/type_check/validate_struct.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Expr<'p>>)>,
) -> Result<TExpr<'p, &'p str>, TypeError> {
let entry = env.scope.get(&sym).ok_or(UndeclaredVar {
sym: sym.to_string(),
Expand All @@ -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),
Expand Down

0 comments on commit 152053a

Please sign in to comment.