|
@@ -253,7 +253,37 @@ impl Analyzer {
|
|
|
if let Arg::Lit(v) = arg {
|
|
if let Arg::Lit(v) = arg {
|
|
|
// Match this literal type to a VarType for
|
|
// Match this literal type to a VarType for
|
|
|
// type checking.
|
|
// type checking.
|
|
|
|
|
+
|
|
|
let var_type = v.typ.to_vartype();
|
|
let var_type = v.typ.to_vartype();
|
|
|
|
|
+ // TODO: Refactor the Array type checks here and in the Arg::Var
|
|
|
|
|
+ // section so that there is less repetition.
|
|
|
|
|
+ // Validation for Array types
|
|
|
|
|
+ if arg_types[0] == VarType::BaseArray {
|
|
|
|
|
+ if var_type != VarType::Base {
|
|
|
|
|
+ return Err(self.error.abort(
|
|
|
|
|
+ &format!(
|
|
|
|
|
+ "Incorrect argument type. Expected `{:?}`, got `{:?}`.",
|
|
|
|
|
+ VarType::Base,
|
|
|
|
|
+ var_type
|
|
|
|
|
+ ),
|
|
|
|
|
+ v.line,
|
|
|
|
|
+ v.column,
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if arg_types[0] == VarType::ScalarArray {
|
|
|
|
|
+ if var_type != VarType::Scalar {
|
|
|
|
|
+ return Err(self.error.abort(
|
|
|
|
|
+ &format!(
|
|
|
|
|
+ "Incorrect argument type. Expected `{:?}`, got `{:?}`.",
|
|
|
|
|
+ VarType::Scalar,
|
|
|
|
|
+ var_type
|
|
|
|
|
+ ),
|
|
|
|
|
+ v.line,
|
|
|
|
|
+ v.column,
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // Validation for non-Array types
|
|
|
if var_type != arg_types[idx] {
|
|
if var_type != arg_types[idx] {
|
|
|
return Err(self.error.abort(
|
|
return Err(self.error.abort(
|
|
|
&format!(
|
|
&format!(
|
|
@@ -337,6 +367,14 @@ impl Analyzer {
|
|
|
// result on the heap.
|
|
// result on the heap.
|
|
|
if statement.typ == StatementType::Assign {
|
|
if statement.typ == StatementType::Assign {
|
|
|
let mut var = statement.lhs.clone().unwrap();
|
|
let mut var = statement.lhs.clone().unwrap();
|
|
|
|
|
+ // Since we are doing an assignment, ensure that there is a return type.
|
|
|
|
|
+ if return_types.is_empty() {
|
|
|
|
|
+ return Err(self.error.abort(
|
|
|
|
|
+ "Cannot perform assignment without a return type",
|
|
|
|
|
+ var.line,
|
|
|
|
|
+ var.column,
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
var.typ = return_types[0];
|
|
var.typ = return_types[0];
|
|
|
stmt.lhs = Some(var.clone());
|
|
stmt.lhs = Some(var.clone());
|
|
|
heap.push(var.clone());
|
|
heap.push(var.clone());
|