mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
span refactor: fix rebase fallout
This commit is contained in:
parent
508a95b2ba
commit
0e5402773a
@ -37,7 +37,7 @@ pub struct VariableScope<'a> {
|
||||
impl<'a> VariableScope<'a> {
|
||||
pub fn check_shadowing(&self, symbol: &Symbol) -> Result<()> {
|
||||
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 {
|
||||
parent.check_shadowing(symbol)
|
||||
} else {
|
||||
|
@ -41,7 +41,7 @@ impl Display for Declaration {
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct VariableSymbol<'a> {
|
||||
pub type_: &'a Type,
|
||||
pub span: &'a Span,
|
||||
pub span: Span,
|
||||
pub declaration: Declaration,
|
||||
}
|
||||
|
||||
|
@ -39,14 +39,14 @@ fn return_incorrect_type(t1: Option<Type>, t2: Option<Type>, expected: Option<Ty
|
||||
}
|
||||
|
||||
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 {
|
||||
Expression::Identifier(ident) => {
|
||||
if let Some(var) = self.symbol_table.lookup_variable(&ident.name) {
|
||||
Some(self.assert_type(var.type_.clone(), expected, span))
|
||||
} else {
|
||||
self.handler
|
||||
.emit_err(TypeCheckerError::unknown_sym("variable", ident.name, span).into());
|
||||
.emit_err(TypeCheckerError::unknown_sym("variable", ident.name, &span).into());
|
||||
None
|
||||
}
|
||||
}
|
||||
@ -67,7 +67,7 @@ impl<'a> TypeChecker<'a> {
|
||||
|
||||
if int.parse::<i8>().is_err() {
|
||||
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 => {
|
||||
@ -80,7 +80,7 @@ impl<'a> TypeChecker<'a> {
|
||||
|
||||
if int.parse::<i16>().is_err() {
|
||||
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 => {
|
||||
@ -93,7 +93,7 @@ impl<'a> TypeChecker<'a> {
|
||||
|
||||
if int.parse::<i32>().is_err() {
|
||||
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 => {
|
||||
@ -106,7 +106,7 @@ impl<'a> TypeChecker<'a> {
|
||||
|
||||
if int.parse::<i64>().is_err() {
|
||||
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 => {
|
||||
@ -119,25 +119,25 @@ impl<'a> TypeChecker<'a> {
|
||||
|
||||
if int.parse::<i128>().is_err() {
|
||||
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
|
||||
.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
|
||||
.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
|
||||
.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
|
||||
.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
|
||||
.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()))
|
||||
@ -195,7 +195,7 @@ impl<'a> TypeChecker<'a> {
|
||||
// But Type B was not a unsigned int.
|
||||
(Some(Type::IntegerType(_)), Some(t)) => {
|
||||
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(),
|
||||
);
|
||||
}
|
||||
@ -208,13 +208,13 @@ impl<'a> TypeChecker<'a> {
|
||||
// But Type B was not an int.
|
||||
(Some(Type::Field), Some(t)) => {
|
||||
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.
|
||||
(Some(t), _) => {
|
||||
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,
|
||||
Some(t) => self
|
||||
.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())
|
||||
@ -283,7 +283,7 @@ impl<'a> TypeChecker<'a> {
|
||||
TypeCheckerError::incorrect_num_args_to_call(
|
||||
func.input.len(),
|
||||
call.arguments.len(),
|
||||
call.span(),
|
||||
&call.span(),
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
@ -303,7 +303,7 @@ impl<'a> TypeChecker<'a> {
|
||||
Some(ret)
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -63,10 +63,10 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
|
||||
match &var.declaration {
|
||||
Declaration::Const => self
|
||||
.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
|
||||
.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()),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
@ -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 type_ != expected {
|
||||
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_
|
||||
}
|
||||
|
||||
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() {
|
||||
for t in expected.iter() {
|
||||
if &type_ == t {
|
||||
@ -102,7 +102,7 @@ impl<'a> TypeChecker<'a> {
|
||||
TypeCheckerError::expected_one_type_of(
|
||||
expected.iter().map(|t| t.to_string() + ",").collect::<String>(),
|
||||
type_,
|
||||
span,
|
||||
&span,
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
@ -111,15 +111,15 @@ impl<'a> TypeChecker<'a> {
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user