mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-21 08:31:33 +03:00
span refactor: fix build + simplify &span
This commit is contained in:
parent
0e5402773a
commit
8d915339a0
@ -38,7 +38,7 @@ impl TryFrom<(Type, Expression)> for InputValue {
|
|||||||
match (type_, value) {
|
match (type_, value) {
|
||||||
(Type::Address, ValueExpression::Address(value, _)) => Self::Address(value),
|
(Type::Address, ValueExpression::Address(value, _)) => Self::Address(value),
|
||||||
(Type::Boolean, ValueExpression::Boolean(value, span)) => {
|
(Type::Boolean, ValueExpression::Boolean(value, span)) => {
|
||||||
let bool_value = value.parse::<bool>().map_err(|_| ParserError::unexpected_eof(&span))?; // TODO: change error
|
let bool_value = value.parse::<bool>().map_err(|_| ParserError::unexpected_eof(span))?; // TODO: change error
|
||||||
Self::Boolean(bool_value)
|
Self::Boolean(bool_value)
|
||||||
}
|
}
|
||||||
(Type::Char, ValueExpression::Char(value)) => Self::Char(value),
|
(Type::Char, ValueExpression::Char(value)) => Self::Char(value),
|
||||||
@ -48,18 +48,18 @@ impl TryFrom<(Type, Expression)> for InputValue {
|
|||||||
if expected == actual {
|
if expected == actual {
|
||||||
Self::Integer(expected, value)
|
Self::Integer(expected, value)
|
||||||
} else {
|
} else {
|
||||||
return Err(InputError::unexpected_type(expected.to_string(), actual, &span).into());
|
return Err(InputError::unexpected_type(expected.to_string(), actual, span).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(x, y) => {
|
(x, y) => {
|
||||||
return Err(InputError::unexpected_type(x, &y, &y.span()).into());
|
return Err(InputError::unexpected_type(x, &y, y.span()).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(type_, Expression::Unary(unary)) if unary.op == UnaryOperation::Negate => {
|
(type_, Expression::Unary(unary)) if unary.op == UnaryOperation::Negate => {
|
||||||
InputValue::try_from((type_, *unary.inner))?
|
InputValue::try_from((type_, *unary.inner))?
|
||||||
}
|
}
|
||||||
(_type_, expr) => return Err(InputError::illegal_expression(&expr, &expr.span()).into()),
|
(_type_, expr) => return Err(InputError::illegal_expression(&expr, expr.span()).into()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ impl TryFrom<InputAst> for ProgramInput {
|
|||||||
sym::registers => &mut registers,
|
sym::registers => &mut registers,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(
|
return Err(
|
||||||
InputError::unexpected_section(&["main", "registers"], section.name, §ion.span).into(),
|
InputError::unexpected_section(&["main", "registers"], section.name, section.span).into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -39,7 +39,7 @@ impl TryFrom<InputAst> for ProgramState {
|
|||||||
return Err(InputError::unexpected_section(
|
return Err(InputError::unexpected_section(
|
||||||
&["state", "record", "state_leaf"],
|
&["state", "record", "state_leaf"],
|
||||||
section.name,
|
section.name,
|
||||||
§ion.span,
|
section.span,
|
||||||
)
|
)
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
match &console_function_call.function {
|
match &console_function_call.function {
|
||||||
ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted),
|
ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted),
|
||||||
ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted),
|
ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted),
|
||||||
_ => return Err(AstError::impossible_console_assert_call(&args.span).into()),
|
_ => return Err(AstError::impossible_console_assert_call(args.span).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -159,7 +159,7 @@ impl<'a> ParserContext<'a> {
|
|||||||
/// Expects an [`Identifier`], or errors.
|
/// Expects an [`Identifier`], or errors.
|
||||||
pub fn expect_ident(&mut self) -> Result<Identifier> {
|
pub fn expect_ident(&mut self) -> Result<Identifier> {
|
||||||
self.eat_identifier()
|
self.eat_identifier()
|
||||||
.ok_or_else(|| ParserError::unexpected_str(&self.token.token, "ident", &self.token.span).into())
|
.ok_or_else(|| ParserError::unexpected_str(&self.token.token, "ident", self.token.span).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a reference to the next token if it is a [`GroupCoordinate`], or [None] if
|
/// Returns a reference to the next token if it is a [`GroupCoordinate`], or [None] if
|
||||||
@ -250,7 +250,7 @@ impl<'a> ParserContext<'a> {
|
|||||||
|
|
||||||
/// Returns an unexpected error at the current token.
|
/// Returns an unexpected error at the current token.
|
||||||
fn unexpected<T>(&self, expected: impl Display) -> Result<T> {
|
fn unexpected<T>(&self, expected: impl Display) -> Result<T> {
|
||||||
Err(ParserError::unexpected(&self.token.token, expected, &self.token.span).into())
|
Err(ParserError::unexpected(&self.token.token, expected, self.token.span).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Eats the expected `token`, or errors.
|
/// Eats the expected `token`, or errors.
|
||||||
|
@ -230,7 +230,7 @@ impl ParserContext<'_> {
|
|||||||
loop {
|
loop {
|
||||||
if self.eat(&Token::Dot) {
|
if self.eat(&Token::Dot) {
|
||||||
let curr = &self.token;
|
let curr = &self.token;
|
||||||
return Err(ParserError::unexpected_str(&curr.token, "int or ident", &curr.span).into());
|
return Err(ParserError::unexpected_str(&curr.token, "int or ident", curr.span).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.check(&Token::LeftParen) {
|
if !self.check(&Token::LeftParen) {
|
||||||
@ -261,7 +261,7 @@ impl ParserContext<'_> {
|
|||||||
if !trailing && tuple.len() == 1 {
|
if !trailing && tuple.len() == 1 {
|
||||||
Ok(tuple.remove(0))
|
Ok(tuple.remove(0))
|
||||||
} else {
|
} else {
|
||||||
Err(ParserError::unexpected("A tuple expression.", "A valid expression.", &span).into())
|
Err(ParserError::unexpected("A tuple expression.", "A valid expression.", span).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ impl ParserContext<'_> {
|
|||||||
let int_ty = Self::token_to_int_type(suffix).expect("unknown int type token");
|
let int_ty = Self::token_to_int_type(suffix).expect("unknown int type token");
|
||||||
Expression::Value(ValueExpression::Integer(int_ty, value, full_span))
|
Expression::Value(ValueExpression::Integer(int_ty, value, full_span))
|
||||||
}
|
}
|
||||||
None => return Err(ParserError::implicit_values_not_allowed(value, &span).into()),
|
None => return Err(ParserError::implicit_values_not_allowed(value, span).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Token::True => Expression::Value(ValueExpression::Boolean("true".into(), span)),
|
Token::True => Expression::Value(ValueExpression::Boolean("true".into(), span)),
|
||||||
@ -323,7 +323,7 @@ impl ParserContext<'_> {
|
|||||||
span,
|
span,
|
||||||
}),
|
}),
|
||||||
token => {
|
token => {
|
||||||
return Err(ParserError::unexpected_str(token, "expression", &span).into());
|
return Err(ParserError::unexpected_str(token, "expression", span).into());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ impl ParserContext<'_> {
|
|||||||
|
|
||||||
while self.has_next() {
|
while self.has_next() {
|
||||||
match &self.token.token {
|
match &self.token.token {
|
||||||
Token::Ident(sym::test) => return Err(ParserError::test_function(&self.token.span).into()),
|
Token::Ident(sym::test) => return Err(ParserError::test_function(self.token.span).into()),
|
||||||
// Const functions share the first token with the global Const.
|
// Const functions share the first token with the global Const.
|
||||||
Token::Const if self.peek_is_function() => {
|
Token::Const if self.peek_is_function() => {
|
||||||
let (id, function) = self.parse_function_declaration()?;
|
let (id, function) = self.parse_function_declaration()?;
|
||||||
@ -54,7 +54,7 @@ impl ParserContext<'_> {
|
|||||||
.map(|x| format!("'{}'", x))
|
.map(|x| format!("'{}'", x))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", "),
|
.join(", "),
|
||||||
&token.span,
|
token.span,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ impl ParserContext<'_> {
|
|||||||
let constant = self.eat(&Token::Constant).then(|| self.prev_token.span);
|
let constant = self.eat(&Token::Constant).then(|| self.prev_token.span);
|
||||||
let const_ = self.eat(&Token::Const).then(|| self.prev_token.span);
|
let const_ = self.eat(&Token::Const).then(|| self.prev_token.span);
|
||||||
|
|
||||||
if let Some(span) = &const_ {
|
if let Some(span) = const_ {
|
||||||
self.emit_warning(ParserWarning::const_parameter_or_input(span));
|
self.emit_warning(ParserWarning::const_parameter_or_input(span));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,10 +74,10 @@ impl ParserContext<'_> {
|
|||||||
(None, None, None) => Ok(ParamMode::Private),
|
(None, None, None) => Ok(ParamMode::Private),
|
||||||
(Some(_), None, None) => Ok(ParamMode::Public),
|
(Some(_), None, None) => Ok(ParamMode::Public),
|
||||||
(Some(m1), Some(m2), None) | (Some(m1), None, Some(m2)) | (None, Some(m1), Some(m2)) => {
|
(Some(m1), Some(m2), None) | (Some(m1), None, Some(m2)) | (None, Some(m1), Some(m2)) => {
|
||||||
Err(ParserError::inputs_multiple_variable_types_specified(&(m1 + m2)).into())
|
Err(ParserError::inputs_multiple_variable_types_specified(m1 + m2).into())
|
||||||
}
|
}
|
||||||
(Some(m1), Some(m2), Some(m3)) => {
|
(Some(m1), Some(m2), Some(m3)) => {
|
||||||
Err(ParserError::inputs_multiple_variable_types_specified(&(m1 + m2 + m3)).into())
|
Err(ParserError::inputs_multiple_variable_types_specified(m1 + m2 + m3).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ impl ParserContext<'_> {
|
|||||||
let name = self.expect_ident()?;
|
let name = self.expect_ident()?;
|
||||||
|
|
||||||
if let Some(mutable) = &mutable {
|
if let Some(mutable) = &mutable {
|
||||||
self.emit_err(ParserError::mut_function_input(&(mutable.span + name.span)));
|
self.emit_err(ParserError::mut_function_input(mutable.span + name.span));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.expect(&Token::Colon)?;
|
self.expect(&Token::Colon)?;
|
||||||
|
@ -27,7 +27,7 @@ impl ParserContext<'_> {
|
|||||||
if self.check(&Token::LeftSquare) {
|
if self.check(&Token::LeftSquare) {
|
||||||
sections.push(self.parse_section()?);
|
sections.push(self.parse_section()?);
|
||||||
} else {
|
} else {
|
||||||
return Err(ParserError::unexpected_token(self.token.token.clone(), &self.token.span).into());
|
return Err(ParserError::unexpected_token(self.token.token.clone(), self.token.span).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ pub mod type_;
|
|||||||
pub(crate) fn assert_no_whitespace(left_span: Span, right_span: Span, left: &str, right: &str) -> Result<()> {
|
pub(crate) fn assert_no_whitespace(left_span: Span, right_span: Span, left: &str, right: &str) -> Result<()> {
|
||||||
if left_span.hi != right_span.lo {
|
if left_span.hi != right_span.lo {
|
||||||
let error_span = Span::new(left_span.hi, right_span.lo); // The span between them.
|
let error_span = Span::new(left_span.hi, right_span.lo); // The span between them.
|
||||||
return Err(ParserError::unexpected_whitespace(left, right, &error_span).into());
|
return Err(ParserError::unexpected_whitespace(left, right, error_span).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -27,7 +27,7 @@ impl ParserContext<'_> {
|
|||||||
pub fn construct_assignee_access(expr: Expression, _accesses: &mut [AssigneeAccess]) -> Result<Identifier> {
|
pub fn construct_assignee_access(expr: Expression, _accesses: &mut [AssigneeAccess]) -> Result<Identifier> {
|
||||||
match expr {
|
match expr {
|
||||||
Expression::Identifier(id) => Ok(id),
|
Expression::Identifier(id) => Ok(id),
|
||||||
_ => Err(ParserError::invalid_assignment_target(&expr.span()).into()),
|
_ => Err(ParserError::invalid_assignment_target(expr.span()).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ impl ParserContext<'_> {
|
|||||||
let next = if self.eat(&Token::Else) {
|
let next = if self.eat(&Token::Else) {
|
||||||
let s = self.parse_statement()?;
|
let s = self.parse_statement()?;
|
||||||
if !matches!(s, Statement::Block(_) | Statement::Conditional(_)) {
|
if !matches!(s, Statement::Block(_) | Statement::Conditional(_)) {
|
||||||
self.emit_err(ParserError::unexpected_statement(&s, "Block or Conditional", &s.span()));
|
self.emit_err(ParserError::unexpected_statement(&s, "Block or Conditional", s.span()));
|
||||||
}
|
}
|
||||||
Some(Box::new(s))
|
Some(Box::new(s))
|
||||||
} else {
|
} else {
|
||||||
@ -168,7 +168,7 @@ impl ParserContext<'_> {
|
|||||||
string = Some(match token {
|
string = Some(match token {
|
||||||
Token::StringLit(chars) => chars,
|
Token::StringLit(chars) => chars,
|
||||||
_ => {
|
_ => {
|
||||||
p.emit_err(ParserError::unexpected_str(token, "formatted string", &span));
|
p.emit_err(ParserError::unexpected_str(token, "formatted string", span));
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -204,7 +204,7 @@ impl ParserContext<'_> {
|
|||||||
self.emit_err(ParserError::unexpected_ident(
|
self.emit_err(ParserError::unexpected_ident(
|
||||||
x,
|
x,
|
||||||
&["assert", "error", "log"],
|
&["assert", "error", "log"],
|
||||||
&function.span,
|
function.span,
|
||||||
));
|
));
|
||||||
ConsoleFunction::Log(self.parse_console_args()?)
|
ConsoleFunction::Log(self.parse_console_args()?)
|
||||||
}
|
}
|
||||||
@ -219,9 +219,9 @@ impl ParserContext<'_> {
|
|||||||
|
|
||||||
/// Returns a [`VariableName`] AST node if the next tokens represent a variable name with
|
/// Returns a [`VariableName`] AST node if the next tokens represent a variable name with
|
||||||
/// valid keywords.
|
/// valid keywords.
|
||||||
pub fn parse_variable_name(&mut self, decl_ty: Declare, span: &Span) -> Result<VariableName> {
|
pub fn parse_variable_name(&mut self, decl_ty: Declare, span: Span) -> Result<VariableName> {
|
||||||
if self.eat(&Token::Mut) {
|
if self.eat(&Token::Mut) {
|
||||||
self.emit_err(ParserError::let_mut_statement(&(&self.prev_token.span + span)));
|
self.emit_err(ParserError::let_mut_statement(self.prev_token.span + span));
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = self.expect_ident()?;
|
let name = self.expect_ident()?;
|
||||||
@ -244,16 +244,16 @@ impl ParserContext<'_> {
|
|||||||
// Parse variable names.
|
// Parse variable names.
|
||||||
let variable_names = if self.peek_is_left_par() {
|
let variable_names = if self.peek_is_left_par() {
|
||||||
let vars = self
|
let vars = self
|
||||||
.parse_paren_comma_list(|p| p.parse_variable_name(decl_type, &decl_span).map(Some))
|
.parse_paren_comma_list(|p| p.parse_variable_name(decl_type, decl_span).map(Some))
|
||||||
.map(|(vars, ..)| vars)?;
|
.map(|(vars, ..)| vars)?;
|
||||||
|
|
||||||
if vars.len() == 1 {
|
if vars.len() == 1 {
|
||||||
self.emit_err(ParserError::invalid_parens_around_single_variable(&vars[0].span()));
|
self.emit_err(ParserError::invalid_parens_around_single_variable(vars[0].span()));
|
||||||
}
|
}
|
||||||
|
|
||||||
vars
|
vars
|
||||||
} else {
|
} else {
|
||||||
vec![self.parse_variable_name(decl_type, &decl_span)?]
|
vec![self.parse_variable_name(decl_type, decl_span)?]
|
||||||
};
|
};
|
||||||
|
|
||||||
self.expect(&Token::Colon)?;
|
self.expect(&Token::Colon)?;
|
||||||
|
@ -58,7 +58,7 @@ pub(crate) fn tokenize_iter(input: &str, mut lo: BytePos) -> impl '_ + Iterator<
|
|||||||
match token {
|
match token {
|
||||||
Token::WhiteSpace => continue,
|
Token::WhiteSpace => continue,
|
||||||
Token::AddressLit(address) if !check_address(&address) => {
|
Token::AddressLit(address) if !check_address(&address) => {
|
||||||
return Some(Err(ParserError::invalid_address_lit(address, &span).into()));
|
return Some(Err(ParserError::invalid_address_lit(address, span).into()));
|
||||||
}
|
}
|
||||||
_ => return Some(Ok(SpannedToken { token, span })),
|
_ => return Some(Ok(SpannedToken { token, span })),
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ pub struct SymbolTable<'a> {
|
|||||||
impl<'a> SymbolTable<'a> {
|
impl<'a> SymbolTable<'a> {
|
||||||
pub fn check_shadowing(&self, symbol: &Symbol) -> Result<()> {
|
pub fn check_shadowing(&self, symbol: &Symbol) -> Result<()> {
|
||||||
if let Some(function) = self.functions.get(symbol) {
|
if let Some(function) = self.functions.get(symbol) {
|
||||||
Err(AstError::shadowed_function(symbol, &function.span).into())
|
Err(AstError::shadowed_function(symbol, function.span).into())
|
||||||
} else {
|
} else {
|
||||||
self.variables.check_shadowing(symbol)?;
|
self.variables.check_shadowing(symbol)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -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 {
|
||||||
|
@ -46,7 +46,7 @@ impl<'a> TypeChecker<'a> {
|
|||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,17 +63,17 @@ 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()),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(var.type_.clone())
|
Some(var.type_.clone())
|
||||||
} else {
|
} else {
|
||||||
self.handler.emit_err(
|
self.handler.emit_err(
|
||||||
TypeCheckerError::unknown_sym("variable", &input.assignee.identifier.name, &input.assignee.span).into(),
|
TypeCheckerError::unknown_sym("variable", &input.assignee.identifier.name, input.assignee.span).into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
None
|
None
|
||||||
|
@ -83,7 +83,7 @@ impl<'a> TypeChecker<'a> {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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(),
|
||||||
);
|
);
|
||||||
|
@ -96,7 +96,7 @@ macro_rules! create_messages {
|
|||||||
// Formatted errors always takes a span.
|
// Formatted errors always takes a span.
|
||||||
$(#[$error_func_docs])*
|
$(#[$error_func_docs])*
|
||||||
// Expands additional arguments for the error defining function.
|
// Expands additional arguments for the error defining function.
|
||||||
pub fn $name($($arg_names: $arg_types,)* span: &leo_span::Span) -> Self {
|
pub fn $name($($arg_names: $arg_types,)* span: leo_span::Span) -> Self {
|
||||||
Self::Formatted(
|
Self::Formatted(
|
||||||
Formatted::new_from_span(
|
Formatted::new_from_span(
|
||||||
$message,
|
$message,
|
||||||
@ -105,7 +105,7 @@ macro_rules! create_messages {
|
|||||||
Self::code_identifier(),
|
Self::code_identifier(),
|
||||||
Self::message_type(),
|
Self::message_type(),
|
||||||
Self::is_error(),
|
Self::is_error(),
|
||||||
*span,
|
span,
|
||||||
// Each function always generates its own backtrace for backtrace clarity to originate from the error function.
|
// Each function always generates its own backtrace for backtrace clarity to originate from the error function.
|
||||||
Backtrace::new(),
|
Backtrace::new(),
|
||||||
)
|
)
|
||||||
|
@ -282,19 +282,19 @@ mod tests {
|
|||||||
let res: Result<(), _> = Handler::with(|h| {
|
let res: Result<(), _> = Handler::with(|h| {
|
||||||
let s = Span::default();
|
let s = Span::default();
|
||||||
assert_eq!(h.err_count(), 0);
|
assert_eq!(h.err_count(), 0);
|
||||||
h.emit_err(ParserError::invalid_import_list(&s).into());
|
h.emit_err(ParserError::invalid_import_list(s).into());
|
||||||
assert_eq!(h.err_count(), 1);
|
assert_eq!(h.err_count(), 1);
|
||||||
h.emit_err(ParserError::unexpected_eof(&s).into());
|
h.emit_err(ParserError::unexpected_eof(s).into());
|
||||||
assert_eq!(h.err_count(), 2);
|
assert_eq!(h.err_count(), 2);
|
||||||
Err(ParserError::spread_in_array_init(&s).into())
|
Err(ParserError::spread_in_array_init(s).into())
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(count_err(res.unwrap_err().to_string()), 3);
|
assert_eq!(count_err(res.unwrap_err().to_string()), 3);
|
||||||
|
|
||||||
let res: Result<(), _> = Handler::with(|h| {
|
let res: Result<(), _> = Handler::with(|h| {
|
||||||
let s = Span::default();
|
let s = Span::default();
|
||||||
h.emit_err(ParserError::invalid_import_list(&s).into());
|
h.emit_err(ParserError::invalid_import_list(s).into());
|
||||||
h.emit_err(ParserError::unexpected_eof(&s).into());
|
h.emit_err(ParserError::unexpected_eof(s).into());
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
assert_eq!(count_err(res.unwrap_err().to_string()), 2);
|
assert_eq!(count_err(res.unwrap_err().to_string()), 2);
|
||||||
|
Loading…
Reference in New Issue
Block a user