Skip to content

Commit

Permalink
feat: function call checks
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed May 7, 2024
1 parent b94c6a4 commit 637aa8e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 25 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lib/edlang_check/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,21 @@ pub fn lowering_error_to_report(
)
.finish()
}
LoweringError::ParamCountMismatch {
span,
has_args,
needs,
file_id,
} => {
let path = session.file_paths[file_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), span.lo)
.with_code("ParamCountMismatch")
.with_label(
Label::new((path, span.into()))
.with_message(format!("function call parameter count mismatch: has {}, needs {}.", has_args, needs))
.with_color(colors.next()),
)
.finish()
},
}
}
7 changes: 7 additions & 0 deletions lib/edlang_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ pub enum LoweringError {
name: String,
file_id: usize,
},
#[error("parameter count mismatch to function call")]
ParamCountMismatch {
span: Span,
has_args: usize,
needs: usize,
file_id: usize,
},
}
23 changes: 20 additions & 3 deletions lib/edlang_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,12 +1000,29 @@ fn lower_fn_call(
}
};

let mut args = Vec::new();
if args_ty.len() != info.params.len() {
return Err(LoweringError::ParamCountMismatch {
span: info.span,
has_args: info.params.len(),
needs: args_ty.len(),
file_id: builder.file_id,
});
}

assert_eq!(args_ty.len(), info.params.len(), "param length mismatch");
let mut args = Vec::new();

for (arg, arg_ty) in info.params.iter().zip(args_ty) {
let (rvalue, _rvalue_ty, _span) = lower_expr(builder, arg, Some(&arg_ty))?;
let (rvalue, rvalue_ty, arg_span) = lower_expr(builder, arg, Some(&arg_ty))?;

if rvalue_ty != arg_ty.kind {
return Err(LoweringError::UnexpectedType {
span: arg_span,
found: rvalue_ty,
expected: arg_ty,
file_id: builder.file_id,
});
}

args.push(rvalue);
}

Expand Down
Binary file removed program
Binary file not shown.

0 comments on commit 637aa8e

Please sign in to comment.