span refactor: fix rebase fallout

This commit is contained in:
Mazdak Farrokhzad 2022-05-12 16:17:53 +02:00
parent 508a95b2ba
commit 0e5402773a
5 changed files with 29 additions and 29 deletions

View File

@ -37,7 +37,7 @@ pub struct VariableScope<'a> {
impl<'a> VariableScope<'a> { impl<'a> VariableScope<'a> {
pub fn check_shadowing(&self, symbol: &Symbol) -> Result<()> { pub fn check_shadowing(&self, symbol: &Symbol) -> Result<()> {
if let Some(var) = self.variables.get(symbol) { if let Some(var) = self.variables.get(symbol) {
Err(AstError::shadowed_variable(symbol, var.span).into()) Err(AstError::shadowed_variable(symbol, &var.span).into())
} else if let Some(parent) = &self.parent { } else if let Some(parent) = &self.parent {
parent.check_shadowing(symbol) parent.check_shadowing(symbol)
} else { } else {

View File

@ -41,7 +41,7 @@ impl Display for Declaration {
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct VariableSymbol<'a> { pub struct VariableSymbol<'a> {
pub type_: &'a Type, pub type_: &'a Type,
pub span: &'a Span, pub span: Span,
pub declaration: Declaration, pub declaration: Declaration,
} }

View File

@ -39,14 +39,14 @@ fn return_incorrect_type(t1: Option<Type>, t2: Option<Type>, expected: Option<Ty
} }
impl<'a> TypeChecker<'a> { impl<'a> TypeChecker<'a> {
pub(crate) fn compare_expr_type(&mut self, expr: &Expression, expected: Option<Type>, span: &Span) -> Option<Type> { pub(crate) fn compare_expr_type(&mut self, expr: &Expression, expected: Option<Type>, span: Span) -> Option<Type> {
match expr { match expr {
Expression::Identifier(ident) => { Expression::Identifier(ident) => {
if let Some(var) = self.symbol_table.lookup_variable(&ident.name) { if let Some(var) = self.symbol_table.lookup_variable(&ident.name) {
Some(self.assert_type(var.type_.clone(), expected, span)) Some(self.assert_type(var.type_.clone(), expected, span))
} else { } else {
self.handler self.handler
.emit_err(TypeCheckerError::unknown_sym("variable", ident.name, span).into()); .emit_err(TypeCheckerError::unknown_sym("variable", ident.name, &span).into());
None None
} }
} }
@ -67,7 +67,7 @@ impl<'a> TypeChecker<'a> {
if int.parse::<i8>().is_err() { if int.parse::<i8>().is_err() {
self.handler self.handler
.emit_err(TypeCheckerError::invalid_int_value(int, "i8", value.span()).into()); .emit_err(TypeCheckerError::invalid_int_value(int, "i8", &value.span()).into());
} }
} }
IntegerType::I16 => { IntegerType::I16 => {
@ -80,7 +80,7 @@ impl<'a> TypeChecker<'a> {
if int.parse::<i16>().is_err() { if int.parse::<i16>().is_err() {
self.handler self.handler
.emit_err(TypeCheckerError::invalid_int_value(int, "i16", value.span()).into()); .emit_err(TypeCheckerError::invalid_int_value(int, "i16", &value.span()).into());
} }
} }
IntegerType::I32 => { IntegerType::I32 => {
@ -93,7 +93,7 @@ impl<'a> TypeChecker<'a> {
if int.parse::<i32>().is_err() { if int.parse::<i32>().is_err() {
self.handler self.handler
.emit_err(TypeCheckerError::invalid_int_value(int, "i32", value.span()).into()); .emit_err(TypeCheckerError::invalid_int_value(int, "i32", &value.span()).into());
} }
} }
IntegerType::I64 => { IntegerType::I64 => {
@ -106,7 +106,7 @@ impl<'a> TypeChecker<'a> {
if int.parse::<i64>().is_err() { if int.parse::<i64>().is_err() {
self.handler self.handler
.emit_err(TypeCheckerError::invalid_int_value(int, "i64", value.span()).into()); .emit_err(TypeCheckerError::invalid_int_value(int, "i64", &value.span()).into());
} }
} }
IntegerType::I128 => { IntegerType::I128 => {
@ -119,25 +119,25 @@ impl<'a> TypeChecker<'a> {
if int.parse::<i128>().is_err() { if int.parse::<i128>().is_err() {
self.handler self.handler
.emit_err(TypeCheckerError::invalid_int_value(int, "i128", value.span()).into()); .emit_err(TypeCheckerError::invalid_int_value(int, "i128", &value.span()).into());
} }
} }
IntegerType::U8 if str_content.parse::<u8>().is_err() => self IntegerType::U8 if str_content.parse::<u8>().is_err() => self
.handler .handler
.emit_err(TypeCheckerError::invalid_int_value(str_content, "u8", value.span()).into()), .emit_err(TypeCheckerError::invalid_int_value(str_content, "u8", &value.span()).into()),
IntegerType::U16 if str_content.parse::<u16>().is_err() => self IntegerType::U16 if str_content.parse::<u16>().is_err() => self
.handler .handler
.emit_err(TypeCheckerError::invalid_int_value(str_content, "u16", value.span()).into()), .emit_err(TypeCheckerError::invalid_int_value(str_content, "u16", &value.span()).into()),
IntegerType::U32 if str_content.parse::<u32>().is_err() => self IntegerType::U32 if str_content.parse::<u32>().is_err() => self
.handler .handler
.emit_err(TypeCheckerError::invalid_int_value(str_content, "u32", value.span()).into()), .emit_err(TypeCheckerError::invalid_int_value(str_content, "u32", &value.span()).into()),
IntegerType::U64 if str_content.parse::<u64>().is_err() => self IntegerType::U64 if str_content.parse::<u64>().is_err() => self
.handler .handler
.emit_err(TypeCheckerError::invalid_int_value(str_content, "u64", value.span()).into()), .emit_err(TypeCheckerError::invalid_int_value(str_content, "u64", &value.span()).into()),
IntegerType::U128 if str_content.parse::<u128>().is_err() => self IntegerType::U128 if str_content.parse::<u128>().is_err() => self
.handler .handler
.emit_err(TypeCheckerError::invalid_int_value(str_content, "u128", value.span()).into()), .emit_err(TypeCheckerError::invalid_int_value(str_content, "u128", &value.span()).into()),
_ => {} _ => {}
} }
Some(self.assert_type(Type::IntegerType(*type_), expected, value.span())) Some(self.assert_type(Type::IntegerType(*type_), expected, value.span()))
@ -195,7 +195,7 @@ impl<'a> TypeChecker<'a> {
// But Type B was not a unsigned int. // But Type B was not a unsigned int.
(Some(Type::IntegerType(_)), Some(t)) => { (Some(Type::IntegerType(_)), Some(t)) => {
self.handler.emit_err( self.handler.emit_err(
TypeCheckerError::incorrect_pow_exponent_type("unsigned int", t, binary.right.span()) TypeCheckerError::incorrect_pow_exponent_type("unsigned int", t, &binary.right.span())
.into(), .into(),
); );
} }
@ -208,13 +208,13 @@ impl<'a> TypeChecker<'a> {
// But Type B was not an int. // But Type B was not an int.
(Some(Type::Field), Some(t)) => { (Some(Type::Field), Some(t)) => {
self.handler.emit_err( self.handler.emit_err(
TypeCheckerError::incorrect_pow_exponent_type("int", t, binary.right.span()).into(), TypeCheckerError::incorrect_pow_exponent_type("int", t, &binary.right.span()).into(),
); );
} }
// The base is some type thats not an int or field. // The base is some type thats not an int or field.
(Some(t), _) => { (Some(t), _) => {
self.handler self.handler
.emit_err(TypeCheckerError::incorrect_pow_base_type(t, binary.left.span()).into()); .emit_err(TypeCheckerError::incorrect_pow_base_type(t, &binary.left.span()).into());
} }
_ => {} _ => {}
} }
@ -261,7 +261,7 @@ impl<'a> TypeChecker<'a> {
) => self.negate = !self.negate, ) => self.negate = !self.negate,
Some(t) => self Some(t) => self
.handler .handler
.emit_err(TypeCheckerError::type_is_not_negatable(t, unary.inner.span()).into()), .emit_err(TypeCheckerError::type_is_not_negatable(t, &unary.inner.span()).into()),
_ => {} _ => {}
}; };
self.compare_expr_type(&unary.inner, expected, unary.inner.span()) self.compare_expr_type(&unary.inner, expected, unary.inner.span())
@ -283,7 +283,7 @@ impl<'a> TypeChecker<'a> {
TypeCheckerError::incorrect_num_args_to_call( TypeCheckerError::incorrect_num_args_to_call(
func.input.len(), func.input.len(),
call.arguments.len(), call.arguments.len(),
call.span(), &call.span(),
) )
.into(), .into(),
); );
@ -303,7 +303,7 @@ impl<'a> TypeChecker<'a> {
Some(ret) Some(ret)
} else { } else {
self.handler self.handler
.emit_err(TypeCheckerError::unknown_sym("function", &ident.name, ident.span()).into()); .emit_err(TypeCheckerError::unknown_sym("function", &ident.name, &ident.span()).into());
None None
} }
} }

View File

@ -63,10 +63,10 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
match &var.declaration { match &var.declaration {
Declaration::Const => self Declaration::Const => self
.handler .handler
.emit_err(TypeCheckerError::cannont_assign_to_const_var(var_name, var.span).into()), .emit_err(TypeCheckerError::cannont_assign_to_const_var(var_name, &var.span).into()),
Declaration::Input(ParamMode::Constant) => self Declaration::Input(ParamMode::Constant) => self
.handler .handler
.emit_err(TypeCheckerError::cannont_assign_to_const_input(var_name, var.span).into()), .emit_err(TypeCheckerError::cannont_assign_to_const_input(var_name, &var.span).into()),
_ => {} _ => {}
} }

View File

@ -79,18 +79,18 @@ impl<'a> TypeChecker<'a> {
} }
} }
pub(crate) fn assert_type(&self, type_: Type, expected: Option<Type>, span: &Span) -> Type { pub(crate) fn assert_type(&self, type_: Type, expected: Option<Type>, span: Span) -> Type {
if let Some(expected) = expected { if let Some(expected) = expected {
if type_ != expected { if type_ != expected {
self.handler self.handler
.emit_err(TypeCheckerError::type_should_be(type_.clone(), expected, span).into()); .emit_err(TypeCheckerError::type_should_be(type_.clone(), expected, &span).into());
} }
} }
type_ type_
} }
pub(crate) fn assert_one_of_types(&self, type_: Option<Type>, expected: &[Type], span: &Span) -> Option<Type> { pub(crate) fn assert_one_of_types(&self, type_: Option<Type>, expected: &[Type], span: Span) -> Option<Type> {
if let Some(type_) = type_.clone() { if let Some(type_) = type_.clone() {
for t in expected.iter() { for t in expected.iter() {
if &type_ == t { if &type_ == t {
@ -102,7 +102,7 @@ impl<'a> TypeChecker<'a> {
TypeCheckerError::expected_one_type_of( TypeCheckerError::expected_one_type_of(
expected.iter().map(|t| t.to_string() + ",").collect::<String>(), expected.iter().map(|t| t.to_string() + ",").collect::<String>(),
type_, type_,
span, &span,
) )
.into(), .into(),
); );
@ -111,15 +111,15 @@ impl<'a> TypeChecker<'a> {
type_ type_
} }
pub(crate) fn assert_arith_type(&self, type_: Option<Type>, span: &Span) -> Option<Type> { pub(crate) fn assert_arith_type(&self, type_: Option<Type>, span: Span) -> Option<Type> {
self.assert_one_of_types(type_, ARITHMETIC_TYPES, span) self.assert_one_of_types(type_, ARITHMETIC_TYPES, span)
} }
pub(crate) fn assert_field_or_int_type(&self, type_: Option<Type>, span: &Span) -> Option<Type> { pub(crate) fn assert_field_or_int_type(&self, type_: Option<Type>, span: Span) -> Option<Type> {
self.assert_one_of_types(type_, FIELD_AND_INT_TYPES, span) self.assert_one_of_types(type_, FIELD_AND_INT_TYPES, span)
} }
pub(crate) fn assert_int_type(&self, type_: Option<Type>, span: &Span) -> Option<Type> { pub(crate) fn assert_int_type(&self, type_: Option<Type>, span: Span) -> Option<Type> {
self.assert_one_of_types(type_, INT_TYPES, span) self.assert_one_of_types(type_, INT_TYPES, span)
} }
} }