merge testnet3

This commit is contained in:
collin 2022-04-22 09:07:47 -07:00
commit 4fa9704974
48 changed files with 835 additions and 309 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
**.idea/
*.DS_Store
.vscode
leo.iml
**/process.yml

View File

@ -154,7 +154,7 @@ pub trait ReconstructingReducer {
value: Expression,
) -> Result<DefinitionStatement> {
Ok(DefinitionStatement {
declaration_type: definition.declaration_type.clone(),
declaration_type: definition.declaration_type,
variable_names,
type_,
value,

View File

@ -18,7 +18,7 @@ use crate::{assert_no_whitespace, tokenizer::*, Token, KEYWORD_TOKENS};
use leo_ast::*;
use leo_errors::emitter::Handler;
use leo_errors::{ParserError, Result};
use leo_errors::{ParserError, ParserWarning, Result};
use leo_span::{Span, Symbol};
use std::fmt::Display;
@ -114,7 +114,7 @@ impl<'a> ParserContext<'a> {
Some(idx) => idx,
};
looker(self.tokens.get(idx).unwrap_or_else(|| &self.dummy_eof))
looker(self.tokens.get(idx).unwrap_or(&self.dummy_eof))
}
/// Emit the error `err`.
@ -122,6 +122,11 @@ impl<'a> ParserContext<'a> {
self.handler.emit_err(err.into());
}
/// Emit the error `err`.
pub(crate) fn emit_warning(&self, warning: ParserWarning) {
self.handler.emit_warning(warning.into());
}
/// Returns true if the next token exists.
pub fn has_next(&self) -> bool {
!matches!(self.token.token, Token::Eof)

View File

@ -16,7 +16,7 @@
use super::*;
use leo_errors::{ParserError, Result};
use leo_errors::{ParserError, ParserWarning, Result};
use leo_span::sym;
impl ParserContext<'_> {
@ -69,7 +69,7 @@ impl ParserContext<'_> {
let const_ = self.eat(&Token::Const).then(|| self.prev_token.span.clone());
if let Some(span) = &const_ {
self.emit_err(ParserError::const_parameter_or_input(span));
self.emit_warning(ParserWarning::const_parameter_or_input(span));
}
match (public, constant, const_) {
@ -100,7 +100,7 @@ impl ParserContext<'_> {
}
self.expect(&Token::Colon)?;
let type_ = self.parse_type()?.0;
let type_ = self.parse_all_types()?.0;
Ok(FunctionInput::Variable(FunctionInputVariable::new(
name.clone(),
mode,
@ -124,7 +124,7 @@ impl ParserContext<'_> {
// Parse return type.
let output = if self.eat(&Token::Arrow) {
Some(self.parse_type()?.0)
Some(self.parse_all_types()?.0)
} else {
None
};

View File

@ -65,7 +65,7 @@ impl ParserContext<'_> {
let name = self.expect_ident()?;
self.expect(&Token::Colon)?;
let (type_, span) = self.parse_type()?;
let (type_, span) = self.parse_non_ident_types()?;
self.expect(&Token::Assign)?;
let value = self.parse_primary_expression()?;
self.expect(&Token::Semicolon)?;

View File

@ -249,8 +249,6 @@ impl ParserContext<'_> {
Token::Const => Declare::Const,
_ => unreachable!("parse_definition_statement_ shouldn't produce this"),
};
dbg!();
// Parse variable names.
let variable_names = if self.peek_is_left_par() {
let vars = self
@ -269,7 +267,7 @@ impl ParserContext<'_> {
// Parse an optional type ascription.
let type_ = self
.eat(&Token::Colon)
.then(|| self.parse_type().map(|t| t.0))
.then(|| self.parse_all_types().map(|t| t.0))
.transpose()?;
self.expect(&Token::Assign)?;

View File

@ -57,23 +57,29 @@ impl ParserContext<'_> {
/// Returns a [`(Type, Span)`] tuple of AST nodes if the next token represents a type.
/// Also returns the span of the parsed token.
pub fn parse_type(&mut self) -> Result<(Type, Span)> {
pub fn parse_non_ident_types(&mut self) -> Result<(Type, Span)> {
let span = self.expect_any(TYPE_TOKENS)?;
Ok((
match &self.prev_token.token {
Token::Field => Type::Field,
Token::Group => Type::Group,
Token::Address => Type::Address,
Token::Bool => Type::Boolean,
Token::Char => Type::Char,
x => Type::IntegerType(Self::token_to_int_type(x).expect("invalid int type")),
},
span,
))
}
/// Returns a [`(Type, Span)`] tuple of AST nodes if the next token represents a type.
/// Also returns the span of the parsed token.
pub fn parse_all_types(&mut self) -> Result<(Type, Span)> {
Ok(if let Some(ident) = self.eat_identifier() {
let span = ident.span.clone();
(Type::Identifier(ident), span)
} else {
let span = self.expect_any(TYPE_TOKENS)?;
(
match &self.prev_token.token {
Token::Field => Type::Field,
Token::Group => Type::Group,
Token::Address => Type::Address,
Token::Bool => Type::Boolean,
Token::Char => Type::Char,
x => Type::IntegerType(Self::token_to_int_type(x).expect("invalid int type")),
},
span,
)
self.parse_non_ident_types()?
})
}
}

View File

@ -71,7 +71,7 @@ fn with_handler<T>(
let mut tokens = ParserContext::new(&handler, tokens);
let parsed = handler
.extend_if_error(logic(&mut tokens))
.map_err(|_| buf.extract().to_string())?;
.map_err(|_| buf.extract_errs().to_string())?;
not_fully_consumed(&mut tokens)?;
Ok(parsed)
}

View File

@ -46,7 +46,7 @@ pub(crate) fn tokenize_iter<'a>(path: &'a str, input: &'a str) -> impl 'a + Iter
iter::from_fn(move || {
while input.len() > index {
let token = match Token::eat(&input[index..]) {
Err(e) => return Some(Err(e.into())),
Err(e) => return Some(Err(e)),
Ok(t) => t,
};
@ -56,7 +56,7 @@ pub(crate) fn tokenize_iter<'a>(path: &'a str, input: &'a str) -> impl 'a + Iter
if bytes[index] == 0x000D && matches!(bytes.get(index + 1), Some(0x000A)) {
// Check carriage return followed by newline.
line_no += 1;
line_start = index + token_len;
line_start = index + token_len + 1;
index += token_len;
} else if matches!(bytes[index], 0x000A | 0x000D) {
// Check new-line or carriage-return

View File

@ -6,6 +6,15 @@
This directory contains the code for the Errors for all the Leo crates.
The errors are inspired by `rust` in a few different ways:
- Each error has its own unique code.
- Error codes will never be changed upon a stable release.
- Meaning outdated errors will just deprecated.
- In addition we had a unique identifier to let you know where the compiler found the error.
The purpose of these errors is such that searching an error in the documentation, or online for help, becomes easier.
## [Common](./src/common)
The common section of this crate contains a few sub files:

View File

@ -24,37 +24,40 @@ use derivative::Derivative;
/// The indent for an error message.
pub(crate) const INDENT: &str = " ";
/// Backtraced compiler error type
/// Backtraced compiler ouput type
/// undefined value `x`
/// --> file.leo: 2:8
/// = help: Initialize a variable `x` first.
#[derive(Derivative)]
#[derivative(Clone, Debug, Default, Hash, PartialEq)]
pub struct BacktracedError {
pub struct Backtraced {
/// The error message.
pub message: String,
/// The error help message if it exists.
pub help: Option<String>,
/// The error exit code.
pub exit_code: i32,
pub code: i32,
/// The error leading digits identifier.
pub code_identifier: i8,
/// The characters representing the type of error.
pub error_type: String,
pub type_: String,
/// Is this Backtrace a warning or error?
pub error: bool,
#[derivative(PartialEq = "ignore")]
#[derivative(Hash = "ignore")]
/// The backtrace representing where the error occured in Leo.
pub backtrace: Backtrace,
}
impl BacktracedError {
impl Backtraced {
/// Creates a backtraced error from a backtrace.
pub fn new_from_backtrace<S>(
message: S,
help: Option<String>,
exit_code: i32,
code: i32,
code_identifier: i8,
error_type: String,
type_: String,
error: bool,
backtrace: Backtrace,
) -> Self
where
@ -63,14 +66,15 @@ impl BacktracedError {
Self {
message: message.to_string(),
help,
exit_code,
code,
code_identifier,
error_type,
type_,
error,
backtrace,
}
}
/// Gets the backtraced error error code.
/// Gets the backtraced error exit code.
pub fn exit_code(&self) -> i32 {
let mut code: i32;
if self.code_identifier > 99 {
@ -80,7 +84,7 @@ impl BacktracedError {
} else {
code = self.code_identifier as i32 * 1_000;
}
code += self.exit_code;
code += self.code;
code
}
@ -89,20 +93,31 @@ impl BacktracedError {
pub fn error_code(&self) -> String {
format!(
"E{error_type}{code_identifier:0>3}{exit_code:0>4}",
error_type = self.error_type,
error_type = self.type_,
code_identifier = self.code_identifier,
exit_code = self.exit_code,
exit_code = self.code,
)
}
/// Gets a unique warning identifier.
pub fn warning_code(&self) -> String {
format!(
"W{error_type}{code_identifier:0>3}{exit_code:0>4}",
error_type = self.type_,
code_identifier = self.code_identifier,
exit_code = self.code,
)
}
}
impl fmt::Display for BacktracedError {
impl fmt::Display for Backtraced {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let error_message = format!(
"Error [{error_code}]: {message}",
error_code = self.error_code(),
message = self.message,
);
let (kind, code) = if self.error {
("Error", self.error_code())
} else {
("Warning", self.warning_code())
};
let message = format!("{kind} [{code}]: {message}", message = self.message,);
// To avoid the color enabling characters for comparison with test expectations.
if std::env::var("LEO_TESTFRAMEWORK")
@ -111,9 +126,13 @@ impl fmt::Display for BacktracedError {
.to_owned()
.is_empty()
{
write!(f, "{}", error_message.bold().red())?;
if self.error {
write!(f, "{}", message.bold().red())?;
} else {
write!(f, "{}", message.bold().yellow())?;
}
} else {
write!(f, "{}", error_message)?;
write!(f, "{}", message)?;
};
if let Some(help) = &self.help {
@ -151,7 +170,7 @@ impl fmt::Display for BacktracedError {
}
}
impl std::error::Error for BacktracedError {
impl std::error::Error for Backtraced {
fn description(&self) -> &str {
&self.message
}

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{BacktracedError, INDENT};
use crate::{Backtraced, INDENT};
use leo_span::Span;
@ -33,21 +33,23 @@ use std::fmt;
/// = help: Initialize a variable `x` first.
/// Makes use of the same fields as a BacktracedError.
#[derive(Clone, Debug, Default, Hash, PartialEq)]
pub struct FormattedError {
pub struct Formatted {
/// The formatted error span information.
pub span: Span,
/// The backtrace to track where the Leo error originated.
pub backtrace: BacktracedError,
pub backtrace: Backtraced,
}
impl FormattedError {
impl Formatted {
/// Creates a backtraced error from a span and a backtrace.
#[allow(clippy::too_many_arguments)]
pub fn new_from_span<S>(
message: S,
help: Option<String>,
exit_code: i32,
code: i32,
code_identifier: i8,
error_type: String,
type_: String,
error: bool,
span: &Span,
backtrace: Backtrace,
) -> Self
@ -56,18 +58,19 @@ impl FormattedError {
{
Self {
span: span.clone(),
backtrace: BacktracedError::new_from_backtrace(
backtrace: Backtraced::new_from_backtrace(
message.to_string(),
help,
exit_code,
code,
code_identifier,
error_type,
type_,
error,
backtrace,
),
}
}
/// Calls the backtraces error code.
/// Calls the backtraces error exit code.
pub fn exit_code(&self) -> i32 {
self.backtrace.exit_code()
}
@ -76,9 +79,14 @@ impl FormattedError {
pub fn error_code(&self) -> String {
self.backtrace.error_code()
}
/// Returns an warning identifier.
pub fn warning_code(&self) -> String {
self.backtrace.warning_code()
}
}
impl fmt::Display for FormattedError {
impl fmt::Display for Formatted {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let underline = |mut start: usize, mut end: usize| -> String {
if start > end {
@ -101,11 +109,13 @@ impl fmt::Display for FormattedError {
let underlined = underline(self.span.col_start, self.span.col_stop);
let error_message = format!(
"Error [{error_code}]: {message}",
error_code = self.error_code(),
message = self.backtrace.message,
);
let (kind, code) = if self.backtrace.error {
("Error", self.error_code())
} else {
("Warning", self.warning_code())
};
let message = format!("{kind} [{code}]: {message}", message = self.backtrace.message,);
// To avoid the color enabling characters for comparison with test expectations.
if std::env::var("LEO_TESTFRAMEWORK")
@ -114,9 +124,13 @@ impl fmt::Display for FormattedError {
.to_owned()
.is_empty()
{
write!(f, "{}", error_message.bold().red())?;
if self.backtrace.error {
write!(f, "{}", message.bold().red())?;
} else {
write!(f, "{}", message.bold().yellow())?;
}
} else {
write!(f, "{}", error_message)?;
write!(f, "{}", message)?;
};
write!(
@ -183,7 +197,7 @@ impl fmt::Display for FormattedError {
}
}
impl std::error::Error for FormattedError {
impl std::error::Error for Formatted {
fn description(&self) -> &str {
&self.backtrace.message
}

View File

@ -18,7 +18,7 @@
/// and error methods generated through a DSL creates and generates errors
/// with a unique error code.
#[macro_export]
macro_rules! create_errors {
macro_rules! create_messages {
(@step $code:expr,) => {
#[inline(always)]
// Returns the number of unique exit codes that this error type can take on.
@ -26,71 +26,85 @@ macro_rules! create_errors {
$code
}
};
($(#[$error_type_docs:meta])* $error_type:ident, exit_code_mask: $exit_code_mask:expr, error_code_prefix: $error_code_prefix:expr, $($(#[$docs:meta])* @$formatted_or_backtraced_list:ident $names:ident { args: ($($arg_names:ident: $arg_types:ty$(,)?)*), msg: $messages:expr, help: $helps:expr, })*) => {
($(#[$error_type_docs:meta])* $type_:ident, code_mask: $code_mask:expr, code_prefix: $code_prefix:expr, $($(#[$docs:meta])* @$formatted_or_backtraced_list:ident $names:ident { args: ($($arg_names:ident: $arg_types:ty$(,)?)*), msg: $messages:expr, help: $helps:expr, })*) => {
#[allow(unused_imports)] // Allow unused for errors that only use formatted or backtraced errors.
use crate::{BacktracedError, FormattedError, LeoErrorCode};
use crate::{Backtraced, Formatted, LeoMessageCode};
use backtrace::Backtrace;
// Generates the enum and implements from FormattedError and BacktracedErrors.
#[derive(Debug, Error)]
$(#[$error_type_docs])*
pub enum $error_type {
pub enum $type_ {
#[error(transparent)]
FormattedError(#[from] FormattedError),
Formatted(#[from] Formatted),
#[error(transparent)]
BacktracedError(#[from] BacktracedError),
Backtraced(#[from] Backtraced),
}
/// Implements the trait for LeoError Codes.
impl LeoErrorCode for $error_type {
impl LeoMessageCode for $type_ {
#[inline(always)]
fn exit_code(&self) -> i32 {
match self {
Self::FormattedError(formatted) => formatted.exit_code(),
Self::BacktracedError(backtraced) => backtraced.exit_code()
Self::Formatted(formatted) => formatted.exit_code(),
Self::Backtraced(backtraced) => backtraced.exit_code()
}
}
#[inline(always)]
fn error_code(&self) -> String {
match self {
Self::FormattedError(formatted) => formatted.error_code(),
Self::BacktracedError(backtraced) => backtraced.error_code()
Self::Formatted(formatted) => formatted.error_code(),
Self::Backtraced(backtraced) => backtraced.error_code()
}
}
#[inline(always)]
fn exit_code_mask() -> i32 {
$exit_code_mask
fn warning_code(&self) -> String {
match self {
Self::Formatted(formatted) => formatted.warning_code(),
Self::Backtraced(backtraced) => backtraced.warning_code()
}
}
#[inline(always)]
fn error_type() -> String {
$error_code_prefix.to_string()
fn code_mask() -> i32 {
$code_mask
}
#[inline(always)]
fn message_type() -> String {
$code_prefix.to_string()
}
#[inline(always)]
fn is_error() -> bool {
stringify!($type_).contains("Error")
}
}
// Steps over the list of functions with an initial error code of 0.
impl $error_type {
create_errors!(@step 0i32, $(($(#[$docs])* $formatted_or_backtraced_list, $names($($arg_names: $arg_types,)*), $messages, $helps),)*);
// Steps over the list of functions with an initial code of 0.
impl $type_ {
create_messages!(@step 0i32, $(($(#[$docs])* $formatted_or_backtraced_list, $names($($arg_names: $arg_types,)*), $messages, $helps),)*);
}
};
// Matches the function if it is a formatted error.
(@step $code:expr, ($(#[$error_func_docs:meta])* formatted, $error_name:ident($($arg_names:ident: $arg_types:ty,)*), $message:expr, $help:expr), $(($(#[$docs:meta])* $formatted_or_backtraced_tail:ident, $names:ident($($tail_arg_names:ident: $tail_arg_types:ty,)*), $messages:expr, $helps:expr),)*) => {
// Matches the function if it is a formatted message.
(@step $code:expr, ($(#[$error_func_docs:meta])* formatted, $name:ident($($arg_names:ident: $arg_types:ty,)*), $message:expr, $help:expr), $(($(#[$docs:meta])* $formatted_or_backtraced_tail:ident, $names:ident($($tail_arg_names:ident: $tail_arg_types:ty,)*), $messages:expr, $helps:expr),)*) => {
// Formatted errors always takes a span.
$(#[$error_func_docs])*
// Expands additional arguments for the error defining function.
pub fn $error_name($($arg_names: $arg_types,)* span: &leo_span::Span) -> Self {
Self::FormattedError(
FormattedError::new_from_span(
pub fn $name($($arg_names: $arg_types,)* span: &leo_span::Span) -> Self {
Self::Formatted(
Formatted::new_from_span(
$message,
$help,
$code + Self::exit_code_mask(),
$code + Self::code_mask(),
Self::code_identifier(),
Self::error_type(),
Self::message_type(),
Self::is_error(),
span,
// Each function always generates its own backtrace for backtrace clarity to originate from the error function.
Backtrace::new(),
@ -98,28 +112,29 @@ macro_rules! create_errors {
)
}
// Steps the error code value by one and calls on the rest of the functions.
create_errors!(@step $code + 1i32, $(($(#[$docs])* $formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*);
// Steps the code value by one and calls on the rest of the functions.
create_messages!(@step $code + 1i32, $(($(#[$docs])* $formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*);
};
// matches the function if it is a backtraced error.
(@step $code:expr, ($(#[$error_func_docs:meta])* backtraced, $error_name:ident($($arg_names:ident: $arg_types:ty,)*), $message:expr, $help:expr), $(($(#[$docs:meta])* $formatted_or_backtraced_tail:ident, $names:ident($($tail_arg_names:ident: $tail_arg_types:ty,)*), $messages:expr, $helps:expr),)*) => {
// matches the function if it is a backtraced message.
(@step $code:expr, ($(#[$error_func_docs:meta])* backtraced, $name:ident($($arg_names:ident: $arg_types:ty,)*), $message:expr, $help:expr), $(($(#[$docs:meta])* $formatted_or_backtraced_tail:ident, $names:ident($($tail_arg_names:ident: $tail_arg_types:ty,)*), $messages:expr, $helps:expr),)*) => {
$(#[$error_func_docs])*
// Expands additional arguments for the error defining function.
pub fn $error_name($($arg_names: $arg_types,)*) -> Self {
Self::BacktracedError(
BacktracedError::new_from_backtrace(
pub fn $name($($arg_names: $arg_types,)*) -> Self {
Self::Backtraced(
Backtraced::new_from_backtrace(
$message,
$help,
$code + Self::exit_code_mask(),
$code + Self::code_mask(),
Self::code_identifier(),
Self::error_type(),
Self::message_type(),
Self::is_error(),
// Each function always generates its own backtrace for backtrace clarity to originate from the error function.
Backtrace::new(),
)
)
}
// Steps the error code value by one and calls on the rest of the functions.
create_errors!(@step $code + 1i32, $(($(#[$docs])* $formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*);
// Steps the code value by one and calls on the rest of the functions.
create_messages!(@step $code + 1i32, $(($(#[$docs])* $formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*);
};
}

View File

@ -14,19 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
/// ErrorCode trait that all Errors should implement.
pub trait LeoErrorCode: Sized {
/// MessageCode trait that all Errors should implement.
pub trait LeoMessageCode: Sized {
/// Returns the error's exit code for the program.
fn exit_code(&self) -> i32;
/// Returns the prefixed error identifier.
fn error_code(&self) -> String;
/// Returns the error's exit code mask, as to avoid conflicts.
fn exit_code_mask() -> i32;
/// Returns the prefixed warning identifier.
fn warning_code(&self) -> String;
/// Returns the error's code type for the program.
fn error_type() -> String;
/// Returns the messages's exit code mask, as to avoid conflicts.
fn code_mask() -> i32;
/// Returns the message's code type for the program.
fn message_type() -> String;
/// Returns if the message is an error or warning.
fn is_error() -> bool;
/// The LeoErrorCode which has a default code identifier of 037
/// (Leo upsidedown and backwards). This is to make the exit codes

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::LeoWarning;
use super::LeoError;
use core::default::Default;
use core::fmt;
@ -24,6 +26,9 @@ use std::rc::Rc;
pub trait Emitter {
/// Emit the error `err`.
fn emit_err(&mut self, err: LeoError);
/// Emit the warning.
fn emit_warning(&mut self, warning: LeoWarning);
}
/// A trivial `Emitter` using the standard error.
@ -33,6 +38,10 @@ impl Emitter for StderrEmitter {
fn emit_err(&mut self, err: LeoError) {
eprintln!("{}", err);
}
fn emit_warning(&mut self, warning: LeoWarning) {
eprintln!("{warning}");
}
}
/// A buffer of `T`s.
@ -72,34 +81,47 @@ impl<T: fmt::Display> fmt::Display for Buffer<T> {
/// A buffer of `LeoError`s.
pub type ErrBuffer = Buffer<LeoError>;
/// A buffer of `LeoWarning`s.
pub type WarningBuffer = Buffer<LeoWarning>;
/// An `Emitter` that collects into a list.
#[derive(Default, Clone)]
pub struct BufferEmitter(Rc<RefCell<ErrBuffer>>);
pub struct BufferEmitter(Rc<RefCell<ErrBuffer>>, Rc<RefCell<WarningBuffer>>);
impl BufferEmitter {
/// Returns a new buffered emitter.
pub fn new() -> Self {
BufferEmitter(<_>::default())
BufferEmitter(<_>::default(), <_>::default())
}
/// Extracts all the errors collected in this emitter.
pub fn extract(&self) -> ErrBuffer {
pub fn extract_errs(&self) -> ErrBuffer {
self.0.take()
}
/// Extracts all the errors collected in this emitter.
pub fn extract_warnings(&self) -> WarningBuffer {
self.1.take()
}
}
impl Emitter for BufferEmitter {
fn emit_err(&mut self, err: LeoError) {
self.0.borrow_mut().push(err);
}
fn emit_warning(&mut self, warning: LeoWarning) {
self.1.borrow_mut().push(warning);
}
}
/// Contains the actual data for `Handler`.
/// Modelled this way to afford an API using interior mutability.
struct HandlerInner {
/// Number of errors emitted thus far.
count: usize,
err_count: usize,
/// Number of warnings emitted thus far.
warn_count: usize,
/// The sink through which errors will be emitted.
emitter: Box<dyn Emitter>,
}
@ -107,9 +129,15 @@ struct HandlerInner {
impl HandlerInner {
/// Emit the error `err`.
fn emit_err(&mut self, err: LeoError) {
self.count = self.count.saturating_add(1);
self.err_count = self.err_count.saturating_add(1);
self.emitter.emit_err(err);
}
/// Emit the error `err`.
fn emit_warning(&mut self, warning: LeoWarning) {
self.warn_count = self.warn_count.saturating_add(1);
self.emitter.emit_warning(warning);
}
}
/// A handler deals with errors and other compiler output.
@ -128,7 +156,11 @@ impl Default for Handler {
impl Handler {
/// Construct a `Handler` using the given `emitter`.
pub fn new(emitter: Box<dyn Emitter>) -> Self {
let inner = RefCell::new(HandlerInner { count: 0, emitter });
let inner = RefCell::new(HandlerInner {
err_count: 0,
warn_count: 0,
emitter,
});
Self { inner }
}
@ -143,7 +175,7 @@ impl Handler {
/// or if there were none, returns some `T`.
pub fn with<T>(logic: impl for<'a> FnOnce(&'a Handler) -> Result<T, LeoError>) -> Result<T, ErrBuffer> {
let (handler, buf) = Handler::new_with_buf();
handler.extend_if_error(logic(&handler)).map_err(|_| buf.extract())
handler.extend_if_error(logic(&handler)).map_err(|_| buf.extract_errs())
}
/// Emit the error `err`.
@ -151,6 +183,11 @@ impl Handler {
self.inner.borrow_mut().emit_err(err);
}
/// Emit the error `err`.
pub fn emit_warning(&self, warning: LeoWarning) {
self.inner.borrow_mut().emit_warning(warning);
}
/// Emits the error `err`.
/// This will immediately abort compilation.
pub fn fatal_err(&self, err: LeoError) -> ! {
@ -161,7 +198,12 @@ impl Handler {
/// The number of errors thus far.
pub fn err_count(&self) -> usize {
self.inner.borrow().count
self.inner.borrow().err_count
}
/// The number of warnings thus far.
pub fn warning_count(&self) -> usize {
self.inner.borrow().warn_count
}
/// Did we have any errors thus far?

View File

@ -14,17 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::create_errors;
use crate::create_messages;
use std::{
error::Error as ErrorArg,
fmt::{Debug, Display},
};
create_errors!(
create_messages!(
/// AstError enum that represents all the errors for the `leo-ast` crate.
AstError,
exit_code_mask: 2000i32,
error_code_prefix: "AST",
code_mask: 2000i32,
code_prefix: "AST",
/// For when the AST fails to be represented as a JSON string.
@backtraced

View File

@ -14,17 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::create_errors;
use crate::create_messages;
use std::{
error::Error as ErrorArg,
fmt::{Debug, Display},
};
create_errors!(
create_messages!(
/// CliError enum that represents all the errors for the `leo-lang` crate.
CliError,
exit_code_mask: 7000i32,
error_code_prefix: "CLI",
code_mask: 7000i32,
code_prefix: "CLI",
/// Not actually ever returned anywhere outside a test.
@backtraced

View File

@ -14,18 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::create_errors;
use crate::create_messages;
use std::{
error::Error as ErrorArg,
fmt::{Debug, Display},
};
create_errors!(
create_messages!(
/// CompilerError enum that represents all the errors for the `leo-compiler` crate.
CompilerError,
exit_code_mask: 6000i32,
error_code_prefix: "CMP",
code_mask: 6000i32,
code_prefix: "CMP",
/// For when the test function has invalid test context.
@backtraced

View File

@ -14,14 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::create_errors;
use crate::create_messages;
use std::fmt::{Debug, Display};
create_errors!(
create_messages!(
/// InputError enum that represents all the errors for the inputs part of `leo-ast` crate.
InputError,
exit_code_mask: 8000i32,
error_code_prefix: "INP",
code_mask: 8000i32,
code_prefix: "INP",
/// For when declared variable type mismatches actual type.
@formatted

View File

@ -0,0 +1,99 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
/// Contains the ASG error definitions.
use crate::LeoMessageCode;
/// Contains the AST error definitions.
pub mod ast;
pub use self::ast::*;
/// Contains the AST error definitions.
pub mod cli;
pub use self::cli::*;
/// Contains the AST error definitions.
pub mod compiler;
pub use self::compiler::*;
/// Contains the Input error definitions.
pub mod input;
pub use self::input::*;
/// Contains the Package error definitions.
pub mod package;
pub use self::package::*;
/// Contains the Parser error definitions.
pub mod parser;
pub use self::parser::*;
/// The LeoError type that contains all sub error types.
/// This allows a unified error type throughout the Leo crates.
#[derive(Debug, Error)]
pub enum LeoError {
/// Represents an AST Error in a Leo Error.
#[error(transparent)]
AstError(#[from] AstError),
/// Represents an CLI Error in a Leo Error.
#[error(transparent)]
CliError(#[from] CliError),
/// Represents an Compiler Error in a Leo Error.
#[error(transparent)]
CompilerError(#[from] CompilerError),
/// Represents an Input Error in a Leo Error.
#[error(transparent)]
InputError(#[from] InputError),
/// Represents an Package Error in a Leo Error.
#[error(transparent)]
PackageError(#[from] PackageError),
/// Represents an Parser Error in a Leo Error.
#[error(transparent)]
ParserError(#[from] ParserError),
}
impl LeoError {
/// Implement error code for each type of Error.
pub fn error_code(&self) -> String {
use LeoError::*;
match self {
AstError(error) => error.error_code(),
CompilerError(error) => error.error_code(),
CliError(error) => error.error_code(),
InputError(error) => error.error_code(),
ParserError(error) => error.error_code(),
PackageError(error) => error.error_code(),
}
}
/// Implement exit code for each type of Error.
pub fn exit_code(&self) -> i32 {
use LeoError::*;
match self {
AstError(error) => error.exit_code(),
CompilerError(error) => error.exit_code(),
CliError(error) => error.exit_code(),
InputError(error) => error.exit_code(),
ParserError(error) => error.exit_code(),
PackageError(error) => error.exit_code(),
}
}
}
/// A global result type for all Leo crates, that defaults the errors to be a LeoError.
pub type Result<T, E = LeoError> = core::result::Result<T, E>;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::create_errors;
use crate::create_messages;
use std::{
error::Error as ErrorArg,
@ -23,11 +23,11 @@ use std::{
// todo (collin): redo these after Mazdak finishes error indexing.
create_errors!(
create_messages!(
/// PackageError enum that represents all the errors for the `leo-package` crate.
PackageError,
exit_code_mask: 5000i32,
error_code_prefix: "PAK",
code_mask: 5000i32,
code_prefix: "PAK",
/// For when the specified import does not exist.
@backtraced

View File

@ -14,15 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::create_errors;
use crate::create_messages;
use std::fmt::{Debug, Display};
create_errors!(
create_messages!(
/// ParserError enum that represents all the errors for the `leo-parser` crate.
ParserError,
exit_code_mask: 0000i32,
error_code_prefix: "PAR",
code_mask: 0000i32,
code_prefix: "PAR",
/// For when the parser encountered an unexpected token.
@formatted
@ -382,5 +382,4 @@ create_errors!(
msg: "Unicode bidi override code point encountered.",
help: None,
}
);

View File

@ -17,129 +17,20 @@
#![deny(clippy::all, clippy::missing_docs_in_private_items)]
#![doc = include_str!("../README.md")]
/// Contains traits and types for channels through which errors go.
pub mod emitter;
/// Contains the ASG error definitions.
pub mod asg;
pub use self::asg::*;
/// Contains the AST error definitions.
pub mod ast;
pub use self::ast::*;
/// Contains the CLI error definitions.
pub mod cli;
pub use self::cli::*;
#[macro_use]
extern crate thiserror;
/// Contains the common functionalities for defining errors..
#[macro_use]
pub mod common;
pub use self::common::*;
/// Contains the Compiler error definitions.
pub mod compiler;
pub use self::compiler::*;
/// Contains traits and types for channels through which errors go.
pub mod emitter;
/// Contains the errors for the Leo lang.
pub mod errors;
pub use self::errors::*;
/// Contains the Import error definitions.
pub mod import;
pub use self::import::*;
/// Contains the Input error definitions.
pub mod input;
pub use self::input::*;
/// Contains the Package error definitions.
pub mod package;
pub use self::package::*;
/// Contains the Parser error definitions.
pub mod parser;
pub use self::parser::*;
/// Contains the State error definitions.
pub mod state;
pub use self::state::*;
#[macro_use]
extern crate thiserror;
/// The LeoError type that contains all sub error types.
/// This allows a unified error type throughout the Leo crates.
#[derive(Debug, Error)]
pub enum LeoError {
/// Represents an ASG Error in a Leo Error.
#[error(transparent)]
AsgError(#[from] AsgError),
/// Represents an AST Error in a Leo Error.
#[error(transparent)]
AstError(#[from] AstError),
/// Represents an CLI Error in a Leo Error.
#[error(transparent)]
CliError(#[from] CliError),
/// Represents an Compiler Error in a Leo Error.
#[error(transparent)]
CompilerError(#[from] CompilerError),
/// Represents an Import Error in a Leo Error.
#[error(transparent)]
ImportError(#[from] ImportError),
/// Represents an Input Error in a Leo Error.
#[error(transparent)]
InputError(#[from] InputError),
/// Represents an Package Error in a Leo Error.
#[error(transparent)]
PackageError(#[from] PackageError),
/// Represents an Parser Error in a Leo Error.
#[error(transparent)]
ParserError(#[from] ParserError),
/// Represents an State Error in a Leo Error.
#[error(transparent)]
StateError(#[from] StateError),
}
impl LeoError {
/// Implement error code for each type of Error. For the unsupported use a default value.
pub fn error_code(&self) -> String {
use LeoError::*;
match self {
AsgError(error) => error.error_code(),
AstError(error) => error.error_code(),
CliError(error) => error.error_code(),
CompilerError(error) => error.error_code(),
ImportError(error) => error.error_code(),
InputError(error) => error.error_code(),
PackageError(error) => error.error_code(),
ParserError(error) => error.error_code(),
StateError(error) => error.error_code(),
}
}
/// Implement exit code for each type of Error, even the ones that don't have one.
pub fn exit_code(&self) -> i32 {
use LeoError::*;
match self {
AsgError(error) => error.exit_code(),
AstError(error) => error.exit_code(),
CliError(error) => error.exit_code(),
CompilerError(error) => error.exit_code(),
ImportError(error) => error.exit_code(),
InputError(error) => error.exit_code(),
PackageError(error) => error.exit_code(),
ParserError(error) => error.exit_code(),
StateError(error) => error.exit_code(),
}
}
}
/// A global result type for all Leo crates, that defaults the errors to be a LeoError.
pub type Result<T, E = LeoError> = core::result::Result<T, E>;
/// Contains the warnings for the Leo lang.
pub mod warnings;
pub use self::warnings::*;

View File

@ -0,0 +1,43 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
/// The LeoError type that contains all sub error types.
/// This allows a unified error type throughout the Leo crates.
use crate::LeoMessageCode;
/// Contains the Parser warning definitions.
pub mod parser;
pub use self::parser::*;
/// The LeoWarning type that contains all sub error types.
/// This allows a unified error type throughout the Leo crates.
#[derive(Debug, Error)]
pub enum LeoWarning {
/// Represents an Parser Error in a Leo Error.
#[error(transparent)]
ParserWarning(#[from] ParserWarning),
}
impl LeoWarning {
/// Implement warning code for each type of Warning.
pub fn error_code(&self) -> String {
use LeoWarning::*;
match self {
ParserWarning(warning) => warning.warning_code(),
}
}
}

View File

@ -0,0 +1,19 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
/// This module contains the Parser error definitions.
pub mod parser_warning;
pub use self::parser_warning::*;

View File

@ -0,0 +1,32 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::create_messages;
create_messages!(
/// ParserWarning enum that represents all the warnings for the `leo-parser` crate.
ParserWarning,
code_mask: 0000i32,
code_prefix: "PAR",
/// For when a user used const on a parameter or input instead of constant.
@formatted
const_parameter_or_input {
args: (),
msg: "`constant` is preferred over `const` for function parameters to indicate a R1CS constant.",
help: None,
}
);

View File

@ -0,0 +1,75 @@
---
namespace: Parse
expectation: Pass
outputs:
- name: ""
expected_input: []
functions:
"{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const x: u8) {}\\\"}\"}":
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const x: u8) {}\\\"}\"}"
input:
- Variable:
identifier: "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function x(const x: u8) {}\\\"}\"}"
mode: Constant
type_:
IntegerType: U8
span:
line_start: 3
line_stop: 3
col_start: 18
col_stop: 19
path: ""
content: "function x(const x: u8) {}"
const_: false
output: ~
core_mapping: ~
block:
statements: []
span:
line_start: 3
line_stop: 3
col_start: 25
col_stop: 27
path: ""
content: "function x(const x: u8) {}"
span:
line_start: 3
line_stop: 3
col_start: 1
col_stop: 27
path: ""
content: "function x(const x: u8) {}"
"{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function y(constant y: u64) {}\\\"}\"}":
identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function y(constant y: u64) {}\\\"}\"}"
input:
- Variable:
identifier: "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":21,\\\"col_stop\\\":22,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function y(constant y: u64) {}\\\"}\"}"
mode: Constant
type_:
IntegerType: U64
span:
line_start: 5
line_stop: 5
col_start: 21
col_stop: 22
path: ""
content: "function y(constant y: u64) {}"
const_: false
output: ~
core_mapping: ~
block:
statements: []
span:
line_start: 5
line_stop: 5
col_start: 29
col_stop: 31
path: ""
content: "function y(constant y: u64) {}"
span:
line_start: 5
line_stop: 5
col_start: 1
col_stop: 31
path: ""
content: "function y(constant y: u64) {}"

View File

@ -2,4 +2,4 @@
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:3:12\n |\n 3 | function x(const input) {\n | ^^^^^\nError [EPAR0370009]: unexpected string: expected 'ident', got 'input'\n --> test:3:18\n |\n 3 | function x(const input) {\n | ^^^^^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got 'input'\n --> test:3:18\n |\n 3 | function x(const input) {\n | ^^^^^"

View File

@ -0,0 +1,5 @@
---
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370009]: unexpected string: expected 'ident', got 'input'\n --> test:3:18\n |\n 3 | function x(const input) {\n | ^^^^^"

View File

@ -2,4 +2,4 @@
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:3:20\n |\n 3 | function x(x: u32, const public y: i32) {\n | ^^^^^\nError [EPAR0370009]: unexpected string: expected 'ident', got 'public'\n --> test:3:26\n |\n 3 | function x(x: u32, const public y: i32) {\n | ^^^^^^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got 'public'\n --> test:3:26\n |\n 3 | function x(x: u32, const public y: i32) {\n | ^^^^^^"

View File

@ -2,4 +2,4 @@
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:3:27\n |\n 3 | function x(x: u32, public const y: i32) {\n | ^^^^^\nError [EPAR0370041]: A parameter cannot be both public and const.\n --> test:3:20\n |\n 3 | function x(x: u32, public const y: i32) {\n | ^^^^^^^^^^^^"
- "Error [EPAR0370041]: A parameter cannot be both public and const.\n --> test:3:20\n |\n 3 | function x(x: u32, public const y: i32) {\n | ^^^^^^^^^^^^"

View File

@ -1,5 +1,275 @@
---
namespace: Input
expectation: Fail
expectation: Pass
outputs:
- "Error [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:4:1\n |\n 4 | const a: bool = true;\n | ^^^^^\nError [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:5:1\n |\n 5 | const b: u8 = 2;\n | ^^^^^\nError [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:6:1\n |\n 6 | const c: field = 0;\n | ^^^^^\nError [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:7:1\n |\n 7 | const d: group = (0, 1)group;\n | ^^^^^\nError [EPAR0370042]: `constant` is preferred over `const` for function parameters to indicate a R1CS constant.\n --> test:8:1\n |\n 8 | const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\n | ^^^^^"
- sections:
- name: main
definitions:
- mode: Constant
type_: Boolean
name: "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const a: bool = true;\\\"}\"}"
value:
Value:
Boolean:
- "true"
- span:
line_start: 4
line_stop: 4
col_start: 18
col_stop: 22
path: ""
content: "const a: bool = true;"
span:
line_start: 4
line_stop: 4
col_start: 10
col_stop: 14
path: ""
content: "const a: bool = true;"
- mode: Constant
type_:
IntegerType: U8
name: "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const b: u8 = 2;\\\"}\"}"
value:
Value:
Implicit:
- "2"
- span:
line_start: 5
line_stop: 5
col_start: 18
col_stop: 19
path: ""
content: "const b: u8 = 2;"
span:
line_start: 5
line_stop: 5
col_start: 10
col_stop: 12
path: ""
content: "const b: u8 = 2;"
- mode: Constant
type_: Field
name: "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const c: field = 0;\\\"}\"}"
value:
Value:
Implicit:
- "0"
- span:
line_start: 6
line_stop: 6
col_start: 18
col_stop: 19
path: ""
content: "const c: field = 0;"
span:
line_start: 6
line_stop: 6
col_start: 10
col_stop: 15
path: ""
content: "const c: field = 0;"
- mode: Constant
type_: Group
name: "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const d: group = (0, 1)group;\\\"}\"}"
value:
Value:
Group:
Tuple:
x:
Number:
- "0"
- span:
line_start: 7
line_stop: 7
col_start: 19
col_stop: 20
path: ""
content: "const d: group = (0, 1)group;"
y:
Number:
- "1"
- span:
line_start: 7
line_stop: 7
col_start: 22
col_stop: 23
path: ""
content: "const d: group = (0, 1)group;"
span:
line_start: 7
line_stop: 7
col_start: 18
col_stop: 29
path: ""
content: "const d: group = (0, 1)group;"
span:
line_start: 7
line_stop: 7
col_start: 10
col_stop: 15
path: ""
content: "const d: group = (0, 1)group;"
- mode: Constant
type_: Address
name: "{\"name\":\"e\",\"span\":\"{\\\"line_start\\\":8,\\\"line_stop\\\":8,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}"
value:
Value:
Address:
- aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8
- span:
line_start: 8
line_stop: 8
col_start: 20
col_stop: 83
path: ""
content: "const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;"
span:
line_start: 8
line_stop: 8
col_start: 10
col_stop: 17
path: ""
content: "const e: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;"
span:
line_start: 3
line_stop: 3
col_start: 2
col_stop: 6
path: ""
content: "[main]"
- name: registers
definitions:
- mode: Private
type_: Boolean
name: "{\"name\":\"r0\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r0: bool = true;\\\"}\"}"
value:
Value:
Boolean:
- "true"
- span:
line_start: 11
line_stop: 11
col_start: 13
col_stop: 17
path: ""
content: "r0: bool = true;"
span:
line_start: 11
line_stop: 11
col_start: 5
col_stop: 9
path: ""
content: "r0: bool = true;"
- mode: Private
type_:
IntegerType: U8
name: "{\"name\":\"r1\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r1: u8 = 2;\\\"}\"}"
value:
Value:
Implicit:
- "2"
- span:
line_start: 12
line_stop: 12
col_start: 13
col_stop: 14
path: ""
content: "r1: u8 = 2;"
span:
line_start: 12
line_stop: 12
col_start: 5
col_stop: 7
path: ""
content: "r1: u8 = 2;"
- mode: Private
type_: Field
name: "{\"name\":\"r2\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r2: field = 0;\\\"}\"}"
value:
Value:
Implicit:
- "0"
- span:
line_start: 13
line_stop: 13
col_start: 13
col_stop: 14
path: ""
content: "r2: field = 0;"
span:
line_start: 13
line_stop: 13
col_start: 5
col_stop: 10
path: ""
content: "r2: field = 0;"
- mode: Private
type_: Group
name: "{\"name\":\"r3\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r3: group = (0, 1)group;\\\"}\"}"
value:
Value:
Group:
Tuple:
x:
Number:
- "0"
- span:
line_start: 14
line_stop: 14
col_start: 14
col_stop: 15
path: ""
content: "r3: group = (0, 1)group;"
y:
Number:
- "1"
- span:
line_start: 14
line_stop: 14
col_start: 17
col_stop: 18
path: ""
content: "r3: group = (0, 1)group;"
span:
line_start: 14
line_stop: 14
col_start: 13
col_stop: 24
path: ""
content: "r3: group = (0, 1)group;"
span:
line_start: 14
line_stop: 14
col_start: 5
col_stop: 10
path: ""
content: "r3: group = (0, 1)group;"
- mode: Private
type_: Address
name: "{\"name\":\"r4\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":1,\\\"col_stop\\\":3,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;\\\"}\"}"
value:
Value:
Address:
- aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8
- span:
line_start: 15
line_stop: 15
col_start: 15
col_stop: 78
path: ""
content: "r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;"
span:
line_start: 15
line_stop: 15
col_start: 5
col_stop: 12
path: ""
content: "r4: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;"
span:
line_start: 10
line_stop: 10
col_start: 2
col_stop: 11
path: ""
content: "[registers]"

View File

@ -0,0 +1,8 @@
/*
namespace: Parse
expectation: Pass
*/
function x(const x: u8) {}
function y(constant y: u64) {}

View File

@ -1,6 +1,6 @@
/*
namespace: Input
expectation: Fail
expectation: Pass
*/
[main]

View File

@ -14,9 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_errors::{
AsgError, AstError, CliError, CompilerError, ImportError, LeoErrorCode, PackageError, ParserError, StateError,
};
use leo_errors::{AstError, InputError, LeoMessageCode, PackageError, ParserError};
use leo_test_framework::{
fetch::find_tests,
output::TestExpectation,
@ -111,60 +109,32 @@ fn run_with_args(opt: Opt) -> Result<(), Box<dyn Error>> {
let mut all_codes = HashSet::new();
collect_error_codes(
&mut all_codes,
AsgError::error_type(),
AsgError::code_identifier(),
AsgError::exit_code_mask(),
AsgError::num_exit_codes(),
);
collect_error_codes(
&mut all_codes,
AstError::error_type(),
AstError::message_type(),
AstError::code_identifier(),
AstError::exit_code_mask(),
AstError::code_mask(),
AstError::num_exit_codes(),
);
collect_error_codes(
&mut all_codes,
CliError::error_type(),
CliError::code_identifier(),
CliError::exit_code_mask(),
CliError::num_exit_codes(),
InputError::message_type(),
InputError::code_identifier(),
InputError::code_mask(),
InputError::num_exit_codes(),
);
collect_error_codes(
&mut all_codes,
CompilerError::error_type(),
CompilerError::code_identifier(),
CompilerError::exit_code_mask(),
CompilerError::num_exit_codes(),
);
collect_error_codes(
&mut all_codes,
ImportError::error_type(),
ImportError::code_identifier(),
ImportError::exit_code_mask(),
ImportError::num_exit_codes(),
);
collect_error_codes(
&mut all_codes,
PackageError::error_type(),
PackageError::message_type(),
PackageError::code_identifier(),
PackageError::exit_code_mask(),
PackageError::code_mask(),
PackageError::num_exit_codes(),
);
collect_error_codes(
&mut all_codes,
ParserError::error_type(),
ParserError::message_type(),
ParserError::code_identifier(),
ParserError::exit_code_mask(),
ParserError::code_mask(),
ParserError::num_exit_codes(),
);
collect_error_codes(
&mut all_codes,
StateError::error_type(),
StateError::code_identifier(),
StateError::exit_code_mask(),
StateError::num_exit_codes(),
);
// Repackage data into values compatible with serde_yaml
let mut covered_errors = serde_yaml::Mapping::new();