diff --git a/compiler/ast/src/functions/core_function.rs b/compiler/ast/src/functions/core_function.rs index 6af63f333c..2c0d6c3583 100644 --- a/compiler/ast/src/functions/core_function.rs +++ b/compiler/ast/src/functions/core_function.rs @@ -17,7 +17,7 @@ use leo_span::{Symbol, sym}; /// A core instruction that maps directly to an AVM bytecode instruction. -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum CoreFunction { BHP256CommitToAddress, BHP256CommitToField, diff --git a/compiler/ast/src/struct/mod.rs b/compiler/ast/src/struct/mod.rs index 61d66f3a37..bd07ee18a9 100644 --- a/compiler/ast/src/struct/mod.rs +++ b/compiler/ast/src/struct/mod.rs @@ -57,7 +57,7 @@ pub struct Composite { impl PartialEq for Composite { fn eq(&self, other: &Self) -> bool { - self.identifier == other.identifier + self.identifier == other.identifier && self.external == other.external } } diff --git a/compiler/ast/src/types/tuple.rs b/compiler/ast/src/types/tuple.rs index 78d3d794d8..74f8d33a9b 100644 --- a/compiler/ast/src/types/tuple.rs +++ b/compiler/ast/src/types/tuple.rs @@ -44,6 +44,14 @@ impl TupleType { impl fmt::Display for TupleType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "({})", self.elements.iter().map(|x| x.to_string()).collect::>().join(",")) + write!(f, "(")?; + let mut iter = self.elements.iter().peekable(); + while let Some(element) = iter.next() { + write!(f, "{element}")?; + if iter.peek().is_some() { + write!(f, ", ")?; + } + } + write!(f, ")") } } diff --git a/compiler/ast/src/types/type_.rs b/compiler/ast/src/types/type_.rs index 645e0de9ed..7ae0b8be17 100644 --- a/compiler/ast/src/types/type_.rs +++ b/compiler/ast/src/types/type_.rs @@ -27,7 +27,7 @@ use snarkvm::prelude::{ use std::fmt; /// Explicit type used for defining a variable or expression type -#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Type { /// The `address` type. Address, @@ -61,56 +61,11 @@ pub enum Type { Unit, /// Placeholder for a type that could not be resolved or was not well-formed. /// Will eventually lead to a compile error. + #[default] Err, } impl Type { - /// - /// Returns `true` if the self `Type` is equal to the other `Type`. - /// - /// Flattens array syntax: `[[u8; 1]; 2] == [u8; (2, 1)] == true` - /// - pub fn eq_flat(&self, other: &Self) -> bool { - match (self, other) { - (Type::Address, Type::Address) - | (Type::Boolean, Type::Boolean) - | (Type::Field, Type::Field) - | (Type::Group, Type::Group) - | (Type::Scalar, Type::Scalar) - | (Type::Signature, Type::Signature) - | (Type::String, Type::String) - | (Type::Unit, Type::Unit) => true, - (Type::Array(left), Type::Array(right)) => { - left.element_type().eq_flat(right.element_type()) && left.length() == right.length() - } - (Type::Identifier(left), Type::Identifier(right)) => left.name == right.name, - (Type::Integer(left), Type::Integer(right)) => left.eq(right), - (Type::Mapping(left), Type::Mapping(right)) => { - left.key.eq_flat(&right.key) && left.value.eq_flat(&right.value) - } - (Type::Tuple(left), Type::Tuple(right)) if left.length() == right.length() => left - .elements() - .iter() - .zip_eq(right.elements().iter()) - .all(|(left_type, right_type)| left_type.eq_flat(right_type)), - (Type::Composite(left), Type::Composite(right)) => { - left.id.name == right.id.name && left.program == right.program - } - (Type::Future(left), Type::Future(right)) - if left.inputs.len() == right.inputs.len() && left.location.is_some() && right.location.is_some() => - { - left.location == right.location - && left - .inputs() - .iter() - .zip_eq(right.inputs().iter()) - .all(|(left_type, right_type)| left_type.eq_flat(right_type)) - } - _ => false, - } - } - - /// /// Returns `true` if the self `Type` is equal to the other `Type` in all aspects besides composite program of origin. /// /// In the case of futures, it also makes sure that if both are not explicit, they are equal. diff --git a/compiler/passes/src/symbol_table_creation/creator.rs b/compiler/passes/src/symbol_table_creation/creator.rs index af4b77e8d4..86bdffd1d4 100644 --- a/compiler/passes/src/symbol_table_creation/creator.rs +++ b/compiler/passes/src/symbol_table_creation/creator.rs @@ -72,7 +72,8 @@ impl<'a> ProgramVisitor<'a> for SymbolTableCreator<'a> { if !input.is_record && !self.structs.insert(input.name()) { return self.handler.emit_err::(AstError::shadowed_struct(input.name(), input.span).into()); } - if let Err(err) = self.symbol_table.insert_struct(Location::new(input.external, input.name()), input) { + let program_name = input.external.or(self.program_name); + if let Err(err) = self.symbol_table.insert_struct(Location::new(program_name, input.name()), input) { self.handler.emit_err(err); } } diff --git a/compiler/passes/src/type_checking/check_expressions.rs b/compiler/passes/src/type_checking/check_expressions.rs index 29a52a1701..85aa401c0c 100644 --- a/compiler/passes/src/type_checking/check_expressions.rs +++ b/compiler/passes/src/type_checking/check_expressions.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{TypeChecker, VariableSymbol}; +use crate::TypeChecker; use leo_ast::*; use leo_errors::{TypeCheckerError, emitter::Handler}; @@ -24,23 +24,9 @@ use snarkvm::console::network::Network; use itertools::Itertools; -fn return_incorrect_type(t1: Option, t2: Option, expected: &Option) -> Option { - match (t1, t2) { - (Some(t1), Some(t2)) if t1 == t2 => Some(t1), - (Some(t1), Some(t2)) => { - if let Some(expected) = expected { - if &t1 != expected { Some(t1) } else { Some(t2) } - } else { - Some(t1) - } - } - (None, Some(_)) | (Some(_), None) | (None, None) => None, - } -} - impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { type AdditionalInput = Option; - type Output = Option; + type Output = Type; fn visit_expression(&mut self, input: &'a Expression, additional: &Self::AdditionalInput) -> Self::Output { let output = match input { @@ -59,11 +45,8 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { Expression::Unary(unary) => self.visit_unary(unary, additional), Expression::Unit(unit) => self.visit_unit(unit, additional), }; - // If the output type is known, add the expression and its associated type to the symbol table. - if let Some(type_) = &output { - self.type_table.insert(input.id(), type_.clone()); - } - // Return the output type. + // Add the expression and its associated type to the symbol table. + self.type_table.insert(input.id(), output.clone()); output } @@ -71,111 +54,100 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { match input { AccessExpression::Array(access) => { // Check that the expression is an array. - let array_type = self.visit_expression(&access.array, &None); - self.assert_array_type(&array_type, access.array.span()); + let this_type = self.visit_expression(&access.array, &None); + self.assert_array_type(&this_type, access.array.span()); // Check that the index is an integer type. let index_type = self.visit_expression(&access.index, &None); self.assert_int_type(&index_type, access.index.span()); // Get the element type of the array. - let element_type = match array_type { - Some(Type::Array(array_type)) => Some(array_type.element_type().clone()), - _ => None, + let Type::Array(array_type) = this_type else { + // We must have already reported an error above, in our type assertion. + return Type::Err; }; + let element_type = array_type.element_type(); + // If the expected type is known, then check that the element type is the same as the expected type. - if let Some(expected) = expected { - self.assert_type(&element_type, expected, input.span()); - } + self.maybe_assert_type(element_type, expected, input.span()); // Return the element type of the array. - return element_type; + element_type.clone() } AccessExpression::AssociatedFunction(access) => { // Check core struct name and function. - if let Some(core_instruction) = self.get_core_function_call(&access.variant, &access.name) { - // Check that operation is not restricted to finalize blocks. - if self.scope_state.variant != Some(Variant::AsyncFunction) - && core_instruction.is_finalize_command() - { - self.emit_err(TypeCheckerError::operation_must_be_in_finalize_block(input.span())); - } + let Some(core_instruction) = self.get_core_function_call(&access.variant, &access.name) else { + self.emit_err(TypeCheckerError::invalid_core_function_call(access, access.span())); + return Type::Err; + }; + // Check that operation is not restricted to finalize blocks. + if self.scope_state.variant != Some(Variant::AsyncFunction) && core_instruction.is_finalize_command() { + self.emit_err(TypeCheckerError::operation_must_be_in_finalize_block(input.span())); + } - // Get the types of the arguments. - let argument_types = access - .arguments - .iter() - .map(|arg| (self.visit_expression(arg, &None), arg.span())) - .collect::>(); + // Get the types of the arguments. + let argument_types = access + .arguments + .iter() + .map(|arg| (self.visit_expression(arg, &None), arg.span())) + .collect::>(); - // Check that the types of the arguments are valid. - let return_type = - self.check_core_function_call(core_instruction.clone(), &argument_types, input.span()); + // Check that the types of the arguments are valid. + let return_type = + self.check_core_function_call(core_instruction.clone(), &argument_types, input.span()); - // Check return type if the expected type is known. - if let Some(expected) = expected { - self.assert_type(&return_type, expected, input.span()); - } + // Check return type if the expected type is known. + self.maybe_assert_type(&return_type, expected, input.span()); - // Await futures here so that can use the argument variable names to lookup. - if core_instruction == CoreFunction::FutureAwait && access.arguments.len() != 1 { - self.emit_err(TypeCheckerError::can_only_await_one_future_at_a_time(access.span)); - return Some(Type::Unit); - } - return return_type; - } else { - self.emit_err(TypeCheckerError::invalid_core_function_call(access, access.span())); + // Await futures here so that can use the argument variable names to lookup. + if core_instruction == CoreFunction::FutureAwait && access.arguments.len() != 1 { + self.emit_err(TypeCheckerError::can_only_await_one_future_at_a_time(access.span)); } + + return_type } AccessExpression::Tuple(access) => { - if let Some(type_) = self.visit_expression(&access.tuple, &None) { - match type_ { - Type::Tuple(tuple) => { - // Check out of range access. - let index = access.index.value(); - if index > tuple.length() - 1 { - self.emit_err(TypeCheckerError::tuple_out_of_range( - index, - tuple.length(), - access.span(), - )); - } else { - // Lookup type of tuple index. - let actual = tuple.elements().get(index).expect("failed to get tuple index").clone(); - // Emit error for mismatched types. - if let Some(expected) = expected { - self.check_eq_types(&Some(actual.clone()), &Some(expected.clone()), access.span()); - } - // Return type of tuple index. - return Some(actual); - } - } - Type::Future(_) => { - // Get the fully inferred type. - if let Some(Type::Future(inferred_f)) = self.type_table.get(&access.tuple.id()) { - // Make sure in range. - if access.index.value() >= inferred_f.inputs().len() { - self.emit_err(TypeCheckerError::invalid_future_access( - access.index.value(), - inferred_f.inputs().len(), - access.span(), - )); - } else { - // Return the type of the input parameter. - return Some(self.assert_and_return_type( - inferred_f.inputs().get(access.index.value()).unwrap().clone(), - expected, - access.span(), - )); - } - } - } - type_ => { - self.emit_err(TypeCheckerError::type_should_be(type_, "tuple", access.span())); - } + let type_ = self.visit_expression(&access.tuple, &None); + + match type_ { + Type::Err => Type::Err, + Type::Tuple(tuple) => { + // Check out of range access. + let index = access.index.value(); + let Some(actual) = tuple.elements().get(index) else { + self.emit_err(TypeCheckerError::tuple_out_of_range(index, tuple.length(), access.span())); + return Type::Err; + }; + + self.maybe_assert_type(actual, expected, access.span()); + + actual.clone() + } + Type::Future(_) => { + // Get the fully inferred type. + let Some(Type::Future(inferred_f)) = self.type_table.get(&access.tuple.id()) else { + // If a future type was not inferred, we will have already reported an error. + return Type::Err; + }; + + let Some(actual) = inferred_f.inputs().get(access.index.value()) else { + self.emit_err(TypeCheckerError::invalid_future_access( + access.index.value(), + inferred_f.inputs().len(), + access.span(), + )); + return Type::Err; + }; + + self.maybe_assert_type(actual, expected, access.span()); + + actual.clone() + } + type_ => { + self.emit_err(TypeCheckerError::type_should_be2(type_, "a tuple or future", access.span())); + Type::Err } - self.emit_err(TypeCheckerError::invalid_core_function_call(access, access.span())); } } AccessExpression::Member(access) => { @@ -185,15 +157,16 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { sym::caller => { // Check that the operation is not invoked in a `finalize` block. self.check_access_allowed("self.caller", false, access.name.span()); - return Some(Type::Address); + Type::Address } sym::signer => { // Check that operation is not invoked in a `finalize` block. self.check_access_allowed("self.signer", false, access.name.span()); - return Some(Type::Address); + Type::Address } _ => { self.emit_err(TypeCheckerError::invalid_self_access(access.name.span())); + Type::Err } }, // If the access expression is of the form `block.`, then check the is valid. @@ -201,14 +174,13 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { sym::height => { // Check that the operation is invoked in a `finalize` block. self.check_access_allowed("block.height", true, access.name.span()); - return Some(self.assert_and_return_type( - Type::Integer(IntegerType::U32), - expected, - input.span(), - )); + let ty = Type::Integer(IntegerType::U32); + self.maybe_assert_type(&ty, expected, input.span()); + ty } _ => { self.emit_err(TypeCheckerError::invalid_block_access(access.name.span())); + Type::Err } }, // If the access expression is of the form `network.`, then check that the is valid. @@ -216,51 +188,51 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { sym::id => { // Check that the operation is not invoked outside a `finalize` block. self.check_access_allowed("network.id", true, access.name.span()); - return Some(Type::Integer(IntegerType::U16)); + let ty = Type::Integer(IntegerType::U16); + self.maybe_assert_type(&ty, expected, input.span()); + ty } _ => { self.emit_err(TypeCheckerError::invalid_block_access(access.name.span())); + Type::Err } }, _ => { // Check that the type of `inner` in `inner.name` is a struct. match self.visit_expression(&access.inner, &None) { - Some(Type::Composite(struct_)) => { + Type::Err => Type::Err, + Type::Composite(struct_) => { // Retrieve the struct definition associated with `identifier`. - let struct_ = self.lookup_struct(struct_.program, struct_.id.name); - if let Some(struct_) = struct_ { - // Check that `access.name` is a member of the struct. - match struct_.members.iter().find(|member| member.name() == access.name.name) { - // Case where `access.name` is a member of the struct. - Some(Member { type_, .. }) => { - // Check that the type of `access.name` is the same as `expected`. - return Some(self.assert_and_return_type( - type_.clone(), - expected, - access.span(), - )); - } - // Case where `access.name` is not a member of the struct. - None => { - self.emit_err(TypeCheckerError::invalid_struct_variable( - access.name, - &struct_, - access.name.span(), - )); - } - } - } else { + let Some(struct_) = self.lookup_struct(struct_.program, struct_.id.name) else { self.emit_err(TypeCheckerError::undefined_type(&access.inner, access.inner.span())); + return Type::Err; + }; + // Check that `access.name` is a member of the struct. + match struct_.members.iter().find(|member| member.name() == access.name.name) { + // Case where `access.name` is a member of the struct. + Some(Member { type_, .. }) => { + // Check that the type of `access.name` is the same as `expected`. + self.maybe_assert_type(type_, expected, access.span()); + type_.clone() + } + // Case where `access.name` is not a member of the struct. + None => { + self.emit_err(TypeCheckerError::invalid_struct_variable( + access.name, + &struct_, + access.name.span(), + )); + Type::Err + } } } - Some(type_) => { - self.emit_err(TypeCheckerError::type_should_be(type_, "struct", access.inner.span())); - } - None => { - self.emit_err(TypeCheckerError::could_not_determine_type( - &access.inner, + type_ => { + self.emit_err(TypeCheckerError::type_should_be2( + type_, + "a struct", access.inner.span(), )); + Type::Err } } } @@ -268,311 +240,266 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { } AccessExpression::AssociatedConstant(access) => { // Check associated constant type and constant name - if let Some(core_constant) = self.get_core_constant(&access.ty, &access.name) { - // Check return type if the expected type is known. - let return_type = Some(core_constant.to_type()); - if let Some(expected) = expected { - self.assert_type(&return_type, expected, input.span()); - } - return return_type; - } else { - self.emit_err(TypeCheckerError::invalid_associated_constant(access, access.span)) - } + let Some(core_constant) = self.get_core_constant(&access.ty, &access.name) else { + self.emit_err(TypeCheckerError::invalid_associated_constant(access, access.span)); + return Type::Err; + }; + let type_ = core_constant.to_type(); + self.maybe_assert_type(&type_, expected, input.span()); + type_ } } - None } fn visit_array(&mut self, input: &'a ArrayExpression, additional: &Self::AdditionalInput) -> Self::Output { - // Get the types of each element expression. - let element_types = - input.elements.iter().map(|element| self.visit_expression(element, &None)).collect::>(); - - // Construct the array type. - let return_type = match element_types.len() { - // The array cannot be empty. - 0 => { - self.emit_err(TypeCheckerError::array_empty(input.span())); - None - } - num_elements => { - if num_elements <= N::MAX_ARRAY_ELEMENTS { - // Check that the element types match. - let mut element_types = element_types.into_iter(); - // Note that this unwrap is safe because we already checked that the array is not empty. - element_types.next().unwrap().map(|first_type| { - // Check that all elements have the same type. - for (element_type, element) in element_types.zip_eq(input.elements.iter().skip(1)) { - self.assert_type(&element_type, &first_type, element.span()); - } - // Return the array type. - Type::Array(ArrayType::new(first_type, NonNegativeNumber::from(input.elements.len()))) - }) - } else { - // The array cannot have more than `MAX_ARRAY_ELEMENTS` elements. - self.emit_err(TypeCheckerError::array_too_large(num_elements, N::MAX_ARRAY_ELEMENTS, input.span())); - None - } + if input.elements.is_empty() { + self.emit_err(TypeCheckerError::array_empty(input.span())); + return Type::Err; + } + + let element_type = self.visit_expression(&input.elements[0], &None); + + if input.elements.len() > N::MAX_ARRAY_ELEMENTS { + self.emit_err(TypeCheckerError::array_too_large(input.elements.len(), N::MAX_ARRAY_ELEMENTS, input.span())); + } + + if element_type == Type::Err { + return Type::Err; + } + + for expression in input.elements[1..].iter() { + let next_type = self.visit_expression(expression, &None); + + if next_type == Type::Err { + return Type::Err; } - }; - // If the expected type is known, then check that the array type is the same as the expected type. - if let Some(expected) = additional { - self.assert_type(&return_type, expected, input.span()); + self.assert_type(&next_type, &element_type, expression.span()); } - // Return the array type. - return_type + let type_ = Type::Array(ArrayType::new(element_type, NonNegativeNumber::from(input.elements.len()))); + + self.maybe_assert_type(&type_, additional, input.span()); + + type_ } fn visit_binary(&mut self, input: &'a BinaryExpression, destination: &Self::AdditionalInput) -> Self::Output { + let assert_same_type = |slf: &Self, t1: &Type, t2: &Type| -> Type { + if t1 == &Type::Err || t2 == &Type::Err { + Type::Err + } else if !slf.eq_user(t1, t2) { + slf.emit_err(TypeCheckerError::operation_types_mismatch(input.op, t1, t2, input.span())); + Type::Err + } else { + t1.clone() + } + }; + match input.op { BinaryOperation::And | BinaryOperation::Or | BinaryOperation::Nand | BinaryOperation::Nor => { - // Only boolean types. - self.assert_bool_type(destination, input.span()); - let t1 = self.visit_expression(&input.left, destination); - let t2 = self.visit_expression(&input.right, destination); - - // Check that both operands have the same type. - self.check_eq_types(&t1, &t2, input.span()); - - return_incorrect_type(t1, t2, destination) + self.maybe_assert_type(&Type::Boolean, destination, input.span()); + self.visit_expression(&input.left, &Some(Type::Boolean)); + self.visit_expression(&input.right, &Some(Type::Boolean)); + Type::Boolean } BinaryOperation::BitwiseAnd | BinaryOperation::BitwiseOr | BinaryOperation::Xor => { - // Only boolean or integer types. - self.assert_bool_int_type(destination, input.span()); - let t1 = self.visit_expression(&input.left, destination); - let t2 = self.visit_expression(&input.right, destination); - - // Check that both operands have the same type. - self.check_eq_types(&t1, &t2, input.span()); - - return_incorrect_type(t1, t2, destination) + let t1 = self.visit_expression(&input.left, &None); + self.assert_bool_int_type(&t1, input.left.span()); + let t2 = self.visit_expression(&input.right, &None); + self.assert_bool_int_type(&t2, input.right.span()); + let result_t = assert_same_type(self, &t1, &t2); + self.maybe_assert_type(&result_t, destination, input.span()); + result_t } BinaryOperation::Add => { - // Only field, group, scalar, or integer types. - self.assert_field_group_scalar_int_type(destination, input.span()); - let t1 = self.visit_expression(&input.left, destination); - let t2 = self.visit_expression(&input.right, destination); + let t1 = self.visit_expression(&input.left, &None); + let t2 = self.visit_expression(&input.right, &None); + let assert_add_type = |type_: &Type, span: Span| { + if !matches!(type_, Type::Err | Type::Field | Type::Group | Type::Scalar | Type::Integer(_)) { + self.emit_err(TypeCheckerError::type_should_be2( + type_, + "a field, group, scalar, or integer", + span, + )); + } + }; - // Check that both operands have the same type. - self.check_eq_types(&t1, &t2, input.span()); + assert_add_type(&t1, input.left.span()); + assert_add_type(&t2, input.right.span()); - return_incorrect_type(t1, t2, destination) - } - BinaryOperation::Sub => { - // Only field, group, or integer types. - self.assert_field_group_int_type(destination, input.span()); - let t1 = self.visit_expression(&input.left, destination); - let t2 = self.visit_expression(&input.right, destination); + let result_t = assert_same_type(self, &t1, &t2); - // Check that both operands have the same type. - self.check_eq_types(&t1, &t2, input.span()); + self.maybe_assert_type(&result_t, destination, input.span()); - return_incorrect_type(t1, t2, destination) + result_t } - BinaryOperation::Mul => { - // Operation returns field, group or integer types. - self.assert_field_group_int_type(destination, input.span()); - + BinaryOperation::Sub => { let t1 = self.visit_expression(&input.left, &None); let t2 = self.visit_expression(&input.right, &None); - // Allow group * scalar multiplication. - match (t1, input.left.span(), t2, input.right.span()) { - (Some(Type::Group), _, other, other_span) | (other, other_span, Some(Type::Group), _) => { - // Other type must be scalar. - self.assert_scalar_type(&other, other_span); + self.assert_field_group_int_type(&t1, input.left.span()); + self.assert_field_group_int_type(&t2, input.right.span()); - // Operation returns group. - self.assert_group_type(destination, input.span()); + let result_t = assert_same_type(self, &t1, &t2); - Some(Type::Group) - } - (Some(Type::Field), _, other, other_span) | (other, other_span, Some(Type::Field), _) => { - // Other type must be field. - self.assert_field_type(&other, other_span); + self.maybe_assert_type(&result_t, destination, input.span()); - // Operation returns field. - self.assert_field_type(destination, input.span()); + result_t + } + BinaryOperation::Mul => { + let t1 = self.visit_expression(&input.left, &None); + let t2 = self.visit_expression(&input.right, &None); - Some(Type::Field) + let result_t = match (&t1, &t2) { + (Type::Err, _) | (_, Type::Err) => Type::Err, + (Type::Group, Type::Scalar) | (Type::Scalar, Type::Group) => Type::Group, + (Type::Field, Type::Field) => Type::Field, + (Type::Integer(integer_type1), Type::Integer(integer_type2)) if integer_type1 == integer_type2 => { + t1.clone() } - (Some(Type::Integer(integer_type)), _, other, other_span) - | (other, other_span, Some(Type::Integer(integer_type)), _) => { - // Other type must be the same integer type. - self.assert_type(&other, &Type::Integer(integer_type), other_span); + _ => { + self.emit_err(TypeCheckerError::mul_types_mismatch(t1, t2, input.span())); + Type::Err + } + }; - // Operation returns the same integer type. - self.assert_type(destination, &Type::Integer(integer_type), input.span()); + self.maybe_assert_type(&result_t, destination, input.span()); - Some(Type::Integer(integer_type)) - } - (left_type, left_span, right_type, right_span) => { - let check_type = |type_: Option, expression: &Expression, span: Span| match type_ { - None => { - self.emit_err(TypeCheckerError::could_not_determine_type(expression, span)); - } - Some(type_) => { - self.emit_err(TypeCheckerError::type_should_be( - type_, - "field, group, integer, or scalar", - span, - )); - } - }; - check_type(left_type, &input.left, left_span); - check_type(right_type, &input.right, right_span); - destination.clone() - } - } + result_t } BinaryOperation::Div => { - // Only field or integer types. - self.assert_field_int_type(destination, input.span()); + let t1 = self.visit_expression(&input.left, &None); + let t2 = self.visit_expression(&input.right, &None); + + self.assert_field_int_type(&t1, input.left.span()); + self.assert_field_int_type(&t2, input.right.span()); - let t1 = self.visit_expression(&input.left, destination); - let t2 = self.visit_expression(&input.right, destination); + let result_t = assert_same_type(self, &t1, &t2); - // Check that both operands have the same type. - self.check_eq_types(&t1, &t2, input.span()); + self.maybe_assert_type(&result_t, destination, input.span()); - return_incorrect_type(t1, t2, destination) + result_t } BinaryOperation::Rem | BinaryOperation::RemWrapped => { - // Only integer types. - self.assert_int_type(destination, input.span()); + let t1 = self.visit_expression(&input.left, &None); + let t2 = self.visit_expression(&input.right, &None); - let t1 = self.visit_expression(&input.left, destination); - let t2 = self.visit_expression(&input.right, destination); + self.assert_int_type(&t1, input.left.span()); + self.assert_int_type(&t2, input.right.span()); + + let result_t = assert_same_type(self, &t1, &t2); - // Check that both operands have the same type. - self.check_eq_types(&t1, &t2, input.span()); + self.maybe_assert_type(&result_t, destination, input.span()); - return_incorrect_type(t1, t2, destination) + result_t } BinaryOperation::Mod => { - // Only unsigned integer types. - self.assert_unsigned_int_type(destination, input.span()); + let t1 = self.visit_expression(&input.left, &None); + let t2 = self.visit_expression(&input.right, &None); - let t1 = self.visit_expression(&input.left, destination); - let t2 = self.visit_expression(&input.right, destination); + self.assert_unsigned_type(&t1, input.left.span()); + self.assert_unsigned_type(&t1, input.right.span()); - // Check that both operands have the same type. - self.check_eq_types(&t1, &t2, input.span()); + let result_t = assert_same_type(self, &t1, &t2); - return_incorrect_type(t1, t2, destination) + self.maybe_assert_type(&result_t, destination, input.span()); + + result_t } BinaryOperation::Pow => { - // Operation returns field or integer types. - self.assert_field_int_type(destination, input.span()); - let t1 = self.visit_expression(&input.left, &None); let t2 = self.visit_expression(&input.right, &None); - // Allow field ^ field. - match (t1, t2) { - (Some(Type::Field), right) => { - // Right must be field. - self.assert_field_type(&right, input.right.span()); - - // Operation returns field. - self.assert_field_type(destination, input.span()); - - Some(Type::Field) + let ty = match (&t1, &t2) { + (Type::Err, _) | (_, Type::Err) => Type::Err, + (Type::Field, Type::Field) => Type::Field, + (base @ Type::Integer(_), t2) => { + if !matches!( + t2, + Type::Integer(IntegerType::U8) + | Type::Integer(IntegerType::U16) + | Type::Integer(IntegerType::U32) + ) { + self.emit_err(TypeCheckerError::pow_types_mismatch(base, t2, input.span())); + } + base.clone() } - (left, Some(Type::Field)) => { - // Left must be field. - self.assert_field_type(&left, input.left.span()); - - // Operation returns field. - self.assert_field_type(destination, input.span()); - - Some(Type::Field) + _ => { + self.emit_err(TypeCheckerError::pow_types_mismatch(t1, t2, input.span())); + Type::Err } - (Some(left), right) => { - // Left type is checked to be an integer by above. - // Right type must be magnitude (u8, u16, u32). - self.assert_magnitude_type(&right, input.right.span()); + }; - // Operation returns left type. - self.assert_type(destination, &left, input.span()); + self.maybe_assert_type(&ty, destination, input.span()); - Some(left) - } - (None, right) => { - // Lhs type is checked to be an integer by above. - // Rhs type must be magnitude (u8, u16, u32). - self.assert_magnitude_type(&right, input.right.span()); - destination.clone() - } - } + ty } BinaryOperation::Eq | BinaryOperation::Neq => { - // Assert first and second address, boolean, field, group, scalar, or integer types. let t1 = self.visit_expression(&input.left, &None); let t2 = self.visit_expression(&input.right, &None); - // Check that the types of the operands are equal. - self.check_eq_types(&t1, &t2, input.span()); + let _ = assert_same_type(self, &t1, &t2); - // Operation returns a boolean. - self.assert_bool_type(destination, input.span()); + self.maybe_assert_type(&Type::Boolean, destination, input.span()); - Some(Type::Boolean) + Type::Boolean } BinaryOperation::Lt | BinaryOperation::Gt | BinaryOperation::Lte | BinaryOperation::Gte => { // Assert left and right are equal field, scalar, or integer types. let t1 = self.visit_expression(&input.left, &None); let t2 = self.visit_expression(&input.right, &None); - match (&t1, &t2) { - (Some(Type::Address), _) | (_, Some(Type::Address)) => { - // Emit an error for address comparison. - self.emit_err(TypeCheckerError::compare_address(input.op, input.span())); + let assert_compare_type = |type_: &Type, span: Span| { + if !matches!(type_, Type::Err | Type::Field | Type::Scalar | Type::Integer(_)) { + self.emit_err(TypeCheckerError::type_should_be2(type_, "a field, scalar, or integer", span)); } - (t1, t2) => { - self.assert_field_scalar_int_type(t1, input.left.span()); - self.assert_field_scalar_int_type(t2, input.right.span()); - } - } + }; + + assert_compare_type(&t1, input.left.span()); + assert_compare_type(&t2, input.right.span()); - // Check that the types of the operands are equal. - self.check_eq_types(&t1, &t2, input.span()); + let _ = assert_same_type(self, &t1, &t2); - // Operation returns a boolean. - self.assert_bool_type(destination, input.span()); + self.maybe_assert_type(&Type::Boolean, destination, input.span()); - Some(Type::Boolean) + Type::Boolean } BinaryOperation::AddWrapped | BinaryOperation::SubWrapped | BinaryOperation::DivWrapped | BinaryOperation::MulWrapped => { - // Only integer types. - self.assert_int_type(destination, input.span); - let t1 = self.visit_expression(&input.left, destination); - let t2 = self.visit_expression(&input.right, destination); + let t1 = self.visit_expression(&input.left, &None); + let t2 = self.visit_expression(&input.right, &None); + + self.assert_int_type(&t1, input.left.span()); + self.assert_int_type(&t2, input.right.span()); - // Check that both operands have the same type. - self.check_eq_types(&t1, &t2, input.span()); + let result_t = assert_same_type(self, &t1, &t2); - return_incorrect_type(t1, t2, destination) + self.maybe_assert_type(&result_t, destination, input.span()); + + result_t } BinaryOperation::Shl | BinaryOperation::ShlWrapped | BinaryOperation::Shr | BinaryOperation::ShrWrapped | BinaryOperation::PowWrapped => { - let t1 = self.visit_expression(&input.left, destination); + let t1 = self.visit_expression(&input.left, &None); let t2 = self.visit_expression(&input.right, &None); - // Assert left and destination are equal integer types. self.assert_int_type(&t1, input.left.span()); - self.assert_int_type(destination, input.span); - // Assert right type is a magnitude (u8, u16, u32). - self.assert_magnitude_type(&t2, input.right.span()); + if !matches!( + &t2, + Type::Err + | Type::Integer(IntegerType::U8) + | Type::Integer(IntegerType::U16) + | Type::Integer(IntegerType::U32) + ) { + self.emit_err(TypeCheckerError::shift_type_magnitude(input.op, t2, input.right.span())); + } t1 } @@ -580,310 +507,288 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { } fn visit_call(&mut self, input: &'a CallExpression, expected: &Self::AdditionalInput) -> Self::Output { - match &*input.function { - // Note that the parser guarantees that `input.function` is always an identifier. - Expression::Identifier(ident) => { - // Note: The function symbol lookup is performed outside of the `if let Some(func) ...` block to avoid a RefCell lifetime bug in Rust. - // Do not move it into the `if let Some(func) ...` block or it will keep `self.symbol_table_creation` alive for the entire block and will be very memory inefficient! - let func = - self.symbol_table.borrow().lookup_fn_symbol(Location::new(input.program, ident.name)).cloned(); - if let Some(func) = func { - // Check that the call is valid. - // Note that this unwrap is safe since we always set the variant before traversing the body of the function. - match self.scope_state.variant.unwrap() { - Variant::AsyncFunction | Variant::Function if !matches!(func.variant, Variant::Inline) => { - self.emit_err(TypeCheckerError::can_only_call_inline_function(input.span)) - } - Variant::Transition | Variant::AsyncTransition - if matches!(func.variant, Variant::Transition) - && input.program.unwrap() == self.scope_state.program_name.unwrap() => - { - self.emit_err(TypeCheckerError::cannot_invoke_call_to_local_transition_function(input.span)) - } - _ => {} - } + // Get the function symbol. + let Expression::Identifier(ident) = &*input.function else { + unreachable!("Parsing guarantees that a function name is always an identifier."); + }; + let func = self.symbol_table.borrow().lookup_fn_symbol(Location::new(input.program, ident.name)).cloned(); - // Check that the call is not to an external `inline` function. - if func.variant == Variant::Inline - && input.program.unwrap() != self.scope_state.program_name.unwrap() - { - self.emit_err(TypeCheckerError::cannot_call_external_inline_function(input.span)); - } - // Async functions return a single future. - let mut ret = if func.variant == Variant::AsyncFunction { - // Type check after resolving the input types. - if let Some(Type::Future(_)) = expected { - Type::Future(FutureType::new( - Vec::new(), - Some(Location::new(input.program, ident.name)), - false, - )) - } else { - self.emit_err(TypeCheckerError::return_type_of_finalize_function_is_future(input.span)); - Type::Unit - } - } else if func.variant == Variant::AsyncTransition { - // Fully infer future type. - let future_type = match self - .async_function_input_types - .get(&Location::new(input.program, Symbol::intern(&format!("finalize/{}", ident.name)))) - { - Some(inputs) => Type::Future(FutureType::new( - inputs.clone(), - Some(Location::new(input.program, ident.name)), - true, - )), - None => { - self.emit_err(TypeCheckerError::async_function_not_found(ident.name, input.span)); - return Some(Type::Future(FutureType::new( - Vec::new(), - Some(Location::new(input.program, ident.name)), - false, - ))); - } - }; - let fully_inferred_type = match func.output_type { - Type::Tuple(tup) => Type::Tuple(TupleType::new( - tup.elements() - .iter() - .map(|t| if matches!(t, Type::Future(_)) { future_type.clone() } else { t.clone() }) - .collect::>(), - )), - Type::Future(_) => future_type, - _ => panic!("Invalid output type for async transition."), - }; - self.assert_and_return_type(fully_inferred_type, expected, input.span()) - } else { - self.assert_and_return_type(func.output_type, expected, input.span()) - }; - - // Check number of function arguments. - if func.input.len() != input.arguments.len() { - self.emit_err(TypeCheckerError::incorrect_num_args_to_call( - func.input.len(), - input.arguments.len(), - input.span(), - )); - } + let Some(func) = func else { + self.emit_err(TypeCheckerError::unknown_sym("function", ident.name, ident.span())); + return Type::Err; + }; - // Check function argument types. - self.scope_state.is_call = true; - let (mut input_futures, mut inferred_finalize_inputs) = (Vec::new(), Vec::new()); - for (expected, argument) in func.input.iter().zip(input.arguments.iter()) { - // Get the type of the expression. If the type is not known, do not attempt to attempt any further inference. - let ty = self.visit_expression(argument, &Some(expected.type_().clone()))?; - // Extract information about futures that are being consumed. - if func.variant == Variant::AsyncFunction && matches!(expected.type_(), Type::Future(_)) { - // Consume the future. - let option_name = match argument { - Expression::Identifier(id) => Some(id.name), - Expression::Access(AccessExpression::Tuple(tuple_access)) => { - if let Expression::Identifier(id) = &*tuple_access.tuple { - Some(id.name) - } else { - None - } - } - _ => None, - }; + // Check that the call is valid. + // We always set the variant before entering the body of a function, so this unwrap works. + match self.scope_state.variant.unwrap() { + Variant::AsyncFunction | Variant::Function if !matches!(func.variant, Variant::Inline) => { + self.emit_err(TypeCheckerError::can_only_call_inline_function(input.span)) + } + Variant::Transition | Variant::AsyncTransition + if matches!(func.variant, Variant::Transition) + && input.program.unwrap() == self.scope_state.program_name.unwrap() => + { + self.emit_err(TypeCheckerError::cannot_invoke_call_to_local_transition_function(input.span)) + } + _ => {} + } - if let Some(name) = option_name { - match self.scope_state.futures.shift_remove(&name) { - Some(future) => { - self.scope_state.call_location = Some(future.clone()); - } - None => { - self.emit_err(TypeCheckerError::unknown_future_consumed(name, argument.span())); - } - } - } + // Check that the call is not to an external `inline` function. + if func.variant == Variant::Inline && input.program.unwrap() != self.scope_state.program_name.unwrap() { + self.emit_err(TypeCheckerError::cannot_call_external_inline_function(input.span)); + } - match argument { - Expression::Identifier(_) - | Expression::Call(_) - | Expression::Access(AccessExpression::Tuple(_)) => { - match self.scope_state.call_location.clone() { - Some(location) => { - // Get the external program and function name. - input_futures.push(location); - // Get the full inferred type. - inferred_finalize_inputs.push(ty); - } - None => { - self.emit_err(TypeCheckerError::unknown_future_consumed( - argument, - argument.span(), - )); - } - } - } - _ => { - self.emit_err(TypeCheckerError::unknown_future_consumed( - "unknown", - argument.span(), - )); - } - } - } else { - inferred_finalize_inputs.push(ty); - } - } - self.scope_state.is_call = false; + // Async functions return a single future. + let mut ret = if func.variant == Variant::AsyncFunction { + // Type check after resolving the input types. + if let Some(Type::Future(_)) = expected { + Type::Future(FutureType::new(Vec::new(), Some(Location::new(input.program, ident.name)), false)) + } else { + self.emit_err(TypeCheckerError::return_type_of_finalize_function_is_future(input.span)); + Type::Unit + } + } else if func.variant == Variant::AsyncTransition { + // Fully infer future type. + let Some(inputs) = self + .async_function_input_types + .get(&Location::new(input.program, Symbol::intern(&format!("finalize/{}", ident.name)))) + else { + self.emit_err(TypeCheckerError::async_function_not_found(ident.name, input.span)); + return Type::Future(FutureType::new( + Vec::new(), + Some(Location::new(input.program, ident.name)), + false, + )); + }; + + let future_type = + Type::Future(FutureType::new(inputs.clone(), Some(Location::new(input.program, ident.name)), true)); + let fully_inferred_type = match func.output_type { + Type::Tuple(tup) => Type::Tuple(TupleType::new( + tup.elements() + .iter() + .map(|t| if matches!(t, Type::Future(_)) { future_type.clone() } else { t.clone() }) + .collect::>(), + )), + Type::Future(_) => future_type, + _ => panic!("Invalid output type for async transition."), + }; + self.assert_and_return_type(fully_inferred_type, expected, input.span()) + } else { + self.assert_and_return_type(func.output_type, expected, input.span()) + }; - // Add the call to the call graph. - let caller_name = match self.scope_state.function { - None => unreachable!("`self.function` is set every time a function is visited."), - Some(func) => func, - }; + // Check number of function arguments. + if func.input.len() != input.arguments.len() { + self.emit_err(TypeCheckerError::incorrect_num_args_to_call( + func.input.len(), + input.arguments.len(), + input.span(), + )); + } - // Don't add external functions to call graph. Since imports are acyclic, these can never produce a cycle. - if input.program.unwrap() == self.scope_state.program_name.unwrap() { - self.call_graph.add_edge(caller_name, ident.name); + // Check function argument types. + self.scope_state.is_call = true; + let (mut input_futures, mut inferred_finalize_inputs) = (Vec::new(), Vec::new()); + for (expected, argument) in func.input.iter().zip(input.arguments.iter()) { + // Get the type of the expression. If the type is not known, do not attempt to attempt any further inference. + let ty = self.visit_expression(argument, &Some(expected.type_().clone())); + if ty == Type::Err { + return Type::Err; + } + // Extract information about futures that are being consumed. + if func.variant == Variant::AsyncFunction && matches!(expected.type_(), Type::Future(_)) { + // Consume the future. + let option_name = match argument { + Expression::Identifier(id) => Some(id.name), + Expression::Access(AccessExpression::Tuple(tuple_access)) => { + if let Expression::Identifier(id) = &*tuple_access.tuple { Some(id.name) } else { None } } + _ => None, + }; - // Propagate futures from async functions and transitions. - if func.variant.is_async_function() { - // Cannot have async calls in a conditional block. - if self.scope_state.is_conditional { - self.emit_err(TypeCheckerError::async_call_in_conditional(input.span)); + if let Some(name) = option_name { + match self.scope_state.futures.shift_remove(&name) { + Some(future) => { + self.scope_state.call_location = Some(future.clone()); } - - // Can only call async functions and external async transitions from an async transition body. - if self.scope_state.variant != Some(Variant::AsyncTransition) { - self.emit_err(TypeCheckerError::async_call_can_only_be_done_from_async_transition( - input.span, - )); + None => { + self.emit_err(TypeCheckerError::unknown_future_consumed(name, argument.span())); } + } + } - if func.variant.is_transition() { - // Cannot call an external async transition after having called the async function. - if self.scope_state.has_called_finalize { - self.emit_err(TypeCheckerError::external_transition_call_must_be_before_finalize( - input.span, - )); + match argument { + Expression::Identifier(_) + | Expression::Call(_) + | Expression::Access(AccessExpression::Tuple(_)) => { + match self.scope_state.call_location.clone() { + Some(location) => { + // Get the external program and function name. + input_futures.push(location); + // Get the full inferred type. + inferred_finalize_inputs.push(ty); } - } else if func.variant.is_function() { - // Can only call an async function once in a transition function body. - if self.scope_state.has_called_finalize { - self.emit_err(TypeCheckerError::must_call_async_function_once(input.span)); - } - // Check that all futures consumed. - if !self.scope_state.futures.is_empty() { - self.emit_err(TypeCheckerError::not_all_futures_consumed( - self.scope_state.futures.iter().map(|(f, _)| f.to_string()).join(", "), - input.span, - )); + None => { + self.emit_err(TypeCheckerError::unknown_future_consumed(argument, argument.span())); } - // Add future locations to symbol table. Unwrap safe since insert function into symbol table during previous pass. - let mut st = self.symbol_table.borrow_mut(); - // Insert futures into symbol table. - st.insert_futures(input.program.unwrap(), ident.name, input_futures).unwrap(); - // Link async transition to the async function that finalizes it. - st.attach_finalize( - self.scope_state.location(), - Location::new(self.scope_state.program_name, ident.name), - ) - .unwrap(); - drop(st); - // Create expectation for finalize inputs that will be checked when checking corresponding finalize function signature. - self.async_function_input_types.insert( - Location::new(self.scope_state.program_name, ident.name), - inferred_finalize_inputs.clone(), - ); - - // Set scope state flag. - self.scope_state.has_called_finalize = true; - - // Update ret to reflect fully inferred future type. - ret = Type::Future(FutureType::new( - inferred_finalize_inputs, - Some(Location::new(input.program, ident.name)), - true, - )); - - // Type check in case the expected type is known. - self.assert_and_return_type(ret.clone(), expected, input.span()); } } + _ => { + self.emit_err(TypeCheckerError::unknown_future_consumed("unknown", argument.span())); + } + } + } else { + inferred_finalize_inputs.push(ty); + } + } + self.scope_state.is_call = false; - // Set call location so that definition statement knows where future comes from. - self.scope_state.call_location = Some(Location::new(input.program, ident.name)); + // Add the call to the call graph. + let Some(caller_name) = self.scope_state.function else { + unreachable!("`self.function` is set every time a function is visited."); + }; - Some(ret) - } else { - self.emit_err(TypeCheckerError::unknown_sym("function", ident.name, ident.span())); - None - } + // Don't add external functions to call graph. Since imports are acyclic, these can never produce a cycle. + if input.program.unwrap() == self.scope_state.program_name.unwrap() { + self.call_graph.add_edge(caller_name, ident.name); + } + + if func.variant.is_transition() + && self.scope_state.variant == Some(Variant::AsyncTransition) + && self.scope_state.has_called_finalize + { + // Cannot call an external async transition after having called the async function. + self.emit_err(TypeCheckerError::external_transition_call_must_be_before_finalize(input.span)); + } + + // Propagate futures from async functions and transitions. + if func.variant.is_async_function() { + // Cannot have async calls in a conditional block. + if self.scope_state.is_conditional { + self.emit_err(TypeCheckerError::async_call_in_conditional(input.span)); + } + + // Can only call async functions and external async transitions from an async transition body. + if self.scope_state.variant != Some(Variant::AsyncTransition) { + self.emit_err(TypeCheckerError::async_call_can_only_be_done_from_async_transition(input.span)); + } + + // Can only call an async function once in a transition function body. + if self.scope_state.has_called_finalize { + self.emit_err(TypeCheckerError::must_call_async_function_once(input.span)); + } + // Check that all futures consumed. + if !self.scope_state.futures.is_empty() { + self.emit_err(TypeCheckerError::not_all_futures_consumed( + self.scope_state.futures.iter().map(|(f, _)| f.to_string()).join(", "), + input.span, + )); } - _ => unreachable!("Parsing guarantees that a function name is always an identifier."), + // Add future locations to symbol table. Unwrap safe since insert function into symbol table during previous pass. + let mut st = self.symbol_table.borrow_mut(); + // Insert futures into symbol table. + st.insert_futures(input.program.unwrap(), ident.name, input_futures).unwrap(); + // Link async transition to the async function that finalizes it. + st.attach_finalize(self.scope_state.location(), Location::new(self.scope_state.program_name, ident.name)) + .unwrap(); + drop(st); + // Create expectation for finalize inputs that will be checked when checking corresponding finalize function signature. + self.async_function_input_types + .insert(Location::new(self.scope_state.program_name, ident.name), inferred_finalize_inputs.clone()); + + // Set scope state flag. + self.scope_state.has_called_finalize = true; + + // Update ret to reflect fully inferred future type. + ret = Type::Future(FutureType::new( + inferred_finalize_inputs, + Some(Location::new(input.program, ident.name)), + true, + )); + + // Type check in case the expected type is known. + self.assert_and_return_type(ret.clone(), expected, input.span()); } + + // Set call location so that definition statement knows where future comes from. + self.scope_state.call_location = Some(Location::new(input.program, ident.name)); + + ret } fn visit_cast(&mut self, input: &'a CastExpression, expected: &Self::AdditionalInput) -> Self::Output { - // Check that the target type of the cast expression is a castable type. - self.assert_castable_type(&Some(input.type_.clone()), input.span()); - - // Check that the expression type is a primitive type. let expression_type = self.visit_expression(&input.expression, &None); - self.assert_castable_type(&expression_type, input.expression.span()); - // Check that the expected type matches the target type. - Some(self.assert_and_return_type(input.type_.clone(), expected, input.span())) + let assert_castable_type = |actual: &Type, span: Span| { + if !matches!( + actual, + Type::Integer(_) | Type::Boolean | Type::Field | Type::Group | Type::Scalar | Type::Address | Type::Err, + ) { + self.emit_err(TypeCheckerError::type_should_be2( + actual, + "an integer, bool, field, group, scalar, or address", + span, + )); + } + }; + + assert_castable_type(&input.type_, input.span()); + + assert_castable_type(&expression_type, input.expression.span()); + + self.maybe_assert_type(&input.type_, expected, input.span()); + + input.type_.clone() } fn visit_struct_init(&mut self, input: &'a StructExpression, additional: &Self::AdditionalInput) -> Self::Output { let struct_ = self.lookup_struct(self.scope_state.program_name, input.name.name).clone(); - if let Some(struct_) = struct_ { - // Check struct type name. - let ret = self.check_expected_struct(&struct_, additional, input.name.span()); - - // Check number of struct members. - if struct_.members.len() != input.members.len() { - self.emit_err(TypeCheckerError::incorrect_num_struct_members( - struct_.members.len(), - input.members.len(), - input.span(), - )); - } + let Some(struct_) = struct_ else { + self.emit_err(TypeCheckerError::unknown_sym("struct", input.name.name, input.name.span())); + return Type::Err; + }; + // Check struct type name. + let type_ = self.check_expected_struct(&struct_, additional, input.name.span()); + + // Check number of struct members. + if struct_.members.len() != input.members.len() { + self.emit_err(TypeCheckerError::incorrect_num_struct_members( + struct_.members.len(), + input.members.len(), + input.span(), + )); + } - // Check struct member types. - struct_.members.iter().for_each(|Member { identifier, type_, .. }| { - // Lookup struct variable name. - if let Some(actual) = input.members.iter().find(|member| member.identifier.name == identifier.name) { - match &actual.expression { - // If `expression` is None, then the member uses the identifier shorthand, e.g. `Foo { a }` - None => self.visit_identifier(&actual.identifier, &Some(type_.clone())), - // Otherwise, visit the associated expression. - Some(expr) => self.visit_expression(expr, &Some(type_.clone())), - }; - } else { - self.emit_err(TypeCheckerError::missing_struct_member( - struct_.identifier, - identifier, - input.span(), - )); + for Member { identifier, type_, .. } in struct_.members.iter() { + if let Some(actual) = input.members.iter().find(|member| member.identifier.name == identifier.name) { + match &actual.expression { + // If `expression` is None, then the member uses the identifier shorthand, e.g. `Foo { a }` + None => self.visit_identifier(&actual.identifier, &Some(type_.clone())), + // Otherwise, visit the associated expression. + Some(expr) => self.visit_expression(expr, &Some(type_.clone())), }; - }); - - Some(ret) - } else { - self.emit_err(TypeCheckerError::unknown_sym("struct", input.name.name, input.name.span())); - None + } else { + self.emit_err(TypeCheckerError::missing_struct_member(struct_.identifier, identifier, input.span())); + }; } + + type_ } // We do not want to panic on `ErrExpression`s in order to propagate as many errors as possible. fn visit_err(&mut self, _input: &'a ErrExpression, _additional: &Self::AdditionalInput) -> Self::Output { - Default::default() + Type::Err } fn visit_identifier(&mut self, input: &'a Identifier, expected: &Self::AdditionalInput) -> Self::Output { let var = self.symbol_table.borrow().lookup_variable(Location::new(None, input.name)).cloned(); if let Some(var) = &var { - Some(self.assert_and_return_type(var.type_.clone(), expected, input.span())) + self.maybe_assert_type(&var.type_, expected, input.span()); + var.type_.clone() } else { self.emit_err(TypeCheckerError::unknown_sym("variable", input.name, input.span())); - None + Type::Err } } @@ -895,73 +800,76 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { } } - Some(match input { - Literal::Address(_, _, _) => self.assert_and_return_type(Type::Address, expected, input.span()), - Literal::Boolean(_, _, _) => self.assert_and_return_type(Type::Boolean, expected, input.span()), - Literal::Field(_, _, _) => self.assert_and_return_type(Type::Field, expected, input.span()), - Literal::Integer(integer_type, string, _, _) => match integer_type { - IntegerType::U8 => { - parse_integer_literal::(self.handler, string, input.span(), "u8"); - self.assert_and_return_type(Type::Integer(IntegerType::U8), expected, input.span()) - } - IntegerType::U16 => { - parse_integer_literal::(self.handler, string, input.span(), "u16"); - self.assert_and_return_type(Type::Integer(IntegerType::U16), expected, input.span()) - } - IntegerType::U32 => { - parse_integer_literal::(self.handler, string, input.span(), "u32"); - self.assert_and_return_type(Type::Integer(IntegerType::U32), expected, input.span()) - } - IntegerType::U64 => { - parse_integer_literal::(self.handler, string, input.span(), "u64"); - self.assert_and_return_type(Type::Integer(IntegerType::U64), expected, input.span()) - } - IntegerType::U128 => { - parse_integer_literal::(self.handler, string, input.span(), "u128"); - self.assert_and_return_type(Type::Integer(IntegerType::U128), expected, input.span()) - } - IntegerType::I8 => { - parse_integer_literal::(self.handler, string, input.span(), "i8"); - self.assert_and_return_type(Type::Integer(IntegerType::I8), expected, input.span()) - } - IntegerType::I16 => { - parse_integer_literal::(self.handler, string, input.span(), "i16"); - self.assert_and_return_type(Type::Integer(IntegerType::I16), expected, input.span()) - } - IntegerType::I32 => { - parse_integer_literal::(self.handler, string, input.span(), "i32"); - self.assert_and_return_type(Type::Integer(IntegerType::I32), expected, input.span()) - } - IntegerType::I64 => { - parse_integer_literal::(self.handler, string, input.span(), "i64"); - self.assert_and_return_type(Type::Integer(IntegerType::I64), expected, input.span()) - } - IntegerType::I128 => { - parse_integer_literal::(self.handler, string, input.span(), "i128"); - self.assert_and_return_type(Type::Integer(IntegerType::I128), expected, input.span()) - } - }, - Literal::Group(_) => self.assert_and_return_type(Type::Group, expected, input.span()), - Literal::Scalar(_, _, _) => self.assert_and_return_type(Type::Scalar, expected, input.span()), - Literal::String(_, _, _) => { + let type_ = match input { + Literal::Address(_, _, _) => Type::Address, + Literal::Boolean(_, _, _) => Type::Boolean, + Literal::Field(_, _, _) => Type::Field, + Literal::Integer(IntegerType::U8, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "u8"); + Type::Integer(IntegerType::U8) + } + Literal::Integer(IntegerType::U16, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "u16"); + Type::Integer(IntegerType::U16) + } + Literal::Integer(IntegerType::U32, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "u32"); + Type::Integer(IntegerType::U32) + } + Literal::Integer(IntegerType::U64, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "u64"); + Type::Integer(IntegerType::U64) + } + Literal::Integer(IntegerType::U128, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "u128"); + Type::Integer(IntegerType::U128) + } + Literal::Integer(IntegerType::I8, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "i8"); + Type::Integer(IntegerType::I8) + } + Literal::Integer(IntegerType::I16, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "i16"); + Type::Integer(IntegerType::I16) + } + Literal::Integer(IntegerType::I32, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "i32"); + Type::Integer(IntegerType::I32) + } + Literal::Integer(IntegerType::I64, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "i64"); + Type::Integer(IntegerType::I64) + } + Literal::Integer(IntegerType::I128, string, ..) => { + parse_integer_literal::(self.handler, string, input.span(), "i128"); + Type::Integer(IntegerType::I128) + } + Literal::Group(_) => Type::Group, + Literal::Scalar(..) => Type::Scalar, + Literal::String(..) => { self.emit_err(TypeCheckerError::strings_are_not_supported(input.span())); - self.assert_and_return_type(Type::String, expected, input.span()) + Type::String } - }) + }; + + self.maybe_assert_type(&type_, expected, input.span()); + + type_ } fn visit_locator(&mut self, input: &'a LocatorExpression, expected: &Self::AdditionalInput) -> Self::Output { - // Check that the locator points to a valid resource in the ST. - let loc_: VariableSymbol; - if let Some(var) = - self.symbol_table.borrow().lookup_variable(Location::new(Some(input.program.name.name), input.name)) - { - loc_ = var.clone(); + let maybe_var = self + .symbol_table + .borrow() + .lookup_variable(Location::new(Some(input.program.name.name), input.name)) + .cloned(); + if let Some(var) = maybe_var { + self.maybe_assert_type(&var.type_, expected, input.span()); + var.type_ } else { self.emit_err(TypeCheckerError::unknown_sym("variable", input.name, input.span())); - return None; + Type::Err } - Some(self.assert_and_return_type(loc_.type_.clone(), expected, input.span())) } fn visit_ternary(&mut self, input: &'a TernaryExpression, expected: &Self::AdditionalInput) -> Self::Output { @@ -970,100 +878,127 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> { let t1 = self.visit_expression(&input.if_true, expected); let t2 = self.visit_expression(&input.if_false, expected); - return_incorrect_type(t1, t2, expected) + if t1 == Type::Err || t2 == Type::Err { + Type::Err + } else if !self.eq_user(&t1, &t2) { + self.emit_err(TypeCheckerError::ternary_branch_mismatch(t1, t2, input.span())); + Type::Err + } else { + t1 + } } fn visit_tuple(&mut self, input: &'a TupleExpression, expected: &Self::AdditionalInput) -> Self::Output { - match input.elements.len() { - 0 | 1 => unreachable!("Parsing guarantees that tuple expressions have at least two elements."), - _ => { - // Check the expected tuple types if they are known. - if let Some(Type::Tuple(expected_types)) = expected { - // Check actual length is equal to expected length. - if expected_types.length() != input.elements.len() { - self.emit_err(TypeCheckerError::incorrect_tuple_length( - expected_types.length(), - input.elements.len(), - input.span(), - )); - } - - expected_types.elements().iter().zip(input.elements.iter()).for_each(|(expected, expr)| { - // Check that the component expression is not a tuple. - if matches!(expr, Expression::Tuple(_)) { - self.emit_err(TypeCheckerError::nested_tuple_expression(expr.span())) - } - self.visit_expression(expr, &Some(expected.clone())); - }); + // Check the expected tuple types if they are known. + let Some(Type::Tuple(expected_types)) = expected else { + self.emit_err(TypeCheckerError::invalid_tuple(input.span())); + return Type::Err; + }; - Some(Type::Tuple(expected_types.clone())) - } else { - // Tuples must be explicitly typed. - self.emit_err(TypeCheckerError::invalid_tuple(input.span())); + // Check actual length is equal to expected length. + if expected_types.length() != input.elements.len() { + self.emit_err(TypeCheckerError::incorrect_tuple_length( + expected_types.length(), + input.elements.len(), + input.span(), + )); + } - None - } + for (expr, expected) in input.elements.iter().zip(expected_types.elements().iter()) { + if matches!(expr, Expression::Tuple(_)) { + self.emit_err(TypeCheckerError::nested_tuple_expression(expr.span())) } + + self.visit_expression(expr, &Some(expected.clone())); } + + Type::Tuple(expected_types.clone()) } fn visit_unary(&mut self, input: &'a UnaryExpression, destination: &Self::AdditionalInput) -> Self::Output { - match input.op { + let assert_signed_int = |slf: &mut Self, type_: &Type| { + if !matches!( + type_, + Type::Err + | Type::Integer(IntegerType::I8) + | Type::Integer(IntegerType::I16) + | Type::Integer(IntegerType::I32) + | Type::Integer(IntegerType::I64) + | Type::Integer(IntegerType::I128) + ) { + slf.emit_err(TypeCheckerError::type_should_be2(type_, "a signed integer", input.span())); + } + }; + + let ty = match input.op { UnaryOperation::Abs => { - // Only signed integer types. - self.assert_signed_int_type(destination, input.span()); - self.visit_expression(&input.receiver, destination) + let type_ = self.visit_expression(&input.receiver, &None); + assert_signed_int(self, &type_); + type_ } UnaryOperation::AbsWrapped => { - // Only signed integer types. - self.assert_signed_int_type(destination, input.span()); - self.visit_expression(&input.receiver, destination) + let type_ = self.visit_expression(&input.receiver, &None); + assert_signed_int(self, &type_); + type_ } UnaryOperation::Double => { - // Only field or group types. - self.assert_field_group_type(destination, input.span()); - self.visit_expression(&input.receiver, destination) + let type_ = self.visit_expression(&input.receiver, &None); + if !matches!(&type_, Type::Err | Type::Field | Type::Group) { + self.emit_err(TypeCheckerError::type_should_be2(&type_, "a field or group", input.span())); + } + type_ } UnaryOperation::Inverse => { - // Only field types. - self.assert_field_type(destination, input.span()); - self.visit_expression(&input.receiver, destination) + let type_ = self.visit_expression(&input.receiver, &None); + self.assert_type(&type_, &Type::Field, input.span()); + type_ } UnaryOperation::Negate => { - let type_ = self.visit_expression(&input.receiver, destination); - - // Only field, group, or signed integer types. - self.assert_field_group_signed_int_type(&type_, input.receiver.span()); + let type_ = self.visit_expression(&input.receiver, &None); + if !matches!(&type_, Type::Err | Type::Integer(_) | Type::Group | Type::Field) { + self.emit_err(TypeCheckerError::type_should_be2( + &type_, + "an integer, group, or field", + input.span(), + )); + } type_ } UnaryOperation::Not => { - // Only boolean or integer types. - self.assert_bool_int_type(destination, input.span()); - self.visit_expression(&input.receiver, destination) + let type_ = self.visit_expression(&input.receiver, &None); + if !matches!(&type_, Type::Err | Type::Boolean | Type::Integer(_)) { + self.emit_err(TypeCheckerError::type_should_be2(&type_, "a bool or integer", input.span())); + } + type_ } UnaryOperation::Square => { - // Only field type. - self.assert_field_type(destination, input.span()); - self.visit_expression(&input.receiver, destination) + let type_ = self.visit_expression(&input.receiver, &None); + self.assert_type(&type_, &Type::Field, input.span()); + type_ } UnaryOperation::SquareRoot => { - // Only field type. - self.assert_field_type(destination, input.span()); - self.visit_expression(&input.receiver, destination) + let type_ = self.visit_expression(&input.receiver, &None); + self.assert_type(&type_, &Type::Field, input.span()); + type_ } UnaryOperation::ToXCoordinate | UnaryOperation::ToYCoordinate => { - // Only field type. - self.assert_field_type(destination, input.span()); - self.visit_expression(&input.receiver, &Some(Type::Group)) + let _operand_type = self.visit_expression(&input.receiver, &Some(Type::Group)); + self.maybe_assert_type(&Type::Field, destination, input.span()); + Type::Field } - } + }; + + self.maybe_assert_type(&ty, destination, input.span()); + + ty } - fn visit_unit(&mut self, input: &'a UnitExpression, _additional: &Self::AdditionalInput) -> Self::Output { + fn visit_unit(&mut self, input: &'a UnitExpression, additional: &Self::AdditionalInput) -> Self::Output { // Unit expression are only allowed inside a return statement. if !self.scope_state.is_return { self.emit_err(TypeCheckerError::unit_expression_only_in_return_statements(input.span())); } - Some(Type::Unit) + self.maybe_assert_type(&Type::Unit, additional, input.span()); + Type::Unit } } diff --git a/compiler/passes/src/type_checking/check_statements.rs b/compiler/passes/src/type_checking/check_statements.rs index 6324281f5b..5c36215ba5 100644 --- a/compiler/passes/src/type_checking/check_statements.rs +++ b/compiler/passes/src/type_checking/check_statements.rs @@ -48,15 +48,17 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> { fn visit_assert(&mut self, input: &'a AssertStatement) { match &input.variant { AssertVariant::Assert(expr) => { - let type_ = self.visit_expression(expr, &Some(Type::Boolean)); - self.assert_bool_type(&type_, expr.span()); + let _type = self.visit_expression(expr, &Some(Type::Boolean)); } AssertVariant::AssertEq(left, right) | AssertVariant::AssertNeq(left, right) => { let t1 = self.visit_expression(left, &None); let t2 = self.visit_expression(right, &None); - // Check that the types are equal. - self.check_eq_types(&t1, &t2, input.span()); + if t1 != Type::Err && t2 != Type::Err && !self.eq_user(&t1, &t2) { + let op = + if matches!(input.variant, AssertVariant::AssertEq(..)) { "assert_eq" } else { "assert_neq" }; + self.emit_err(TypeCheckerError::operation_types_mismatch(op, t1, t2, input.span())); + } } } } @@ -246,7 +248,7 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> { // Insert the variables into the symbol table. match &input.place { Expression::Identifier(identifier) => { - self.insert_variable(inferred_type.clone(), identifier, input.type_.clone(), identifier.span) + self.insert_variable(Some(inferred_type.clone()), identifier, input.type_.clone(), identifier.span) } Expression::Tuple(tuple_expression) => { let tuple_type = match &input.type_ { @@ -264,10 +266,10 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> { } for i in 0..tuple_expression.elements.len() { - let inferred = if let Some(Type::Tuple(inferred_tuple)) = &inferred_type { - inferred_tuple.elements().get(i).cloned() + let inferred = if let Type::Tuple(inferred_tuple) = &inferred_type { + inferred_tuple.elements().get(i).cloned().unwrap_or_default() } else { - None + Type::Err }; let expr = &tuple_expression.elements[i]; let identifier = match expr { @@ -277,7 +279,7 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> { .emit_err(TypeCheckerError::lhs_tuple_element_must_be_an_identifier(expr.span())); } }; - self.insert_variable(inferred, identifier, tuple_type.elements()[i].clone(), identifier.span); + self.insert_variable(Some(inferred), identifier, tuple_type.elements()[i].clone(), identifier.span); } } _ => self.emit_err(TypeCheckerError::lhs_must_be_identifier_or_tuple(input.place.span())), @@ -298,8 +300,7 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> { } fn visit_iteration(&mut self, input: &'a IterationStatement) { - let iter_type = &Some(input.type_.clone()); - self.assert_int_type(iter_type, input.variable.span); + self.assert_int_type(&input.type_, input.variable.span); // Create a new scope for the loop body. let scope_index = self.create_child_scope(); @@ -333,7 +334,7 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> { self.exit_scope(scope_index); // Check that the literal is valid. - self.visit_expression(&input.start, iter_type); + self.visit_expression(&input.start, &Some(input.type_.clone())); // If `input.start` is a valid literal, instantiate it as a value. match &input.start { @@ -353,7 +354,7 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> { _ => self.emit_err(TypeCheckerError::loop_bound_must_be_literal_or_const(input.start.span())), } - self.visit_expression(&input.stop, iter_type); + self.visit_expression(&input.stop, &Some(input.type_.clone())); // If `input.stop` is a valid literal, instantiate it as a value. match &input.stop { diff --git a/compiler/passes/src/type_checking/checker.rs b/compiler/passes/src/type_checking/checker.rs index 764f2fa227..71954a49e9 100644 --- a/compiler/passes/src/type_checking/checker.rs +++ b/compiler/passes/src/type_checking/checker.rs @@ -32,7 +32,7 @@ use snarkvm::console::network::Network; use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; -use std::{cell::RefCell, marker::PhantomData}; +use std::{cell::RefCell, marker::PhantomData, ops::Deref}; pub struct TypeChecker<'a, N: Network> { /// The symbol table for the program. @@ -55,50 +55,6 @@ pub struct TypeChecker<'a, N: Network> { phantom: PhantomData, } -const ADDRESS_TYPE: Type = Type::Address; - -const BOOLEAN_TYPE: Type = Type::Boolean; - -const FIELD_TYPE: Type = Type::Field; - -const GROUP_TYPE: Type = Type::Group; - -const SCALAR_TYPE: Type = Type::Scalar; - -const SIGNATURE_TYPE: Type = Type::Signature; - -const INT_TYPES: [Type; 10] = [ - Type::Integer(IntegerType::I8), - Type::Integer(IntegerType::I16), - Type::Integer(IntegerType::I32), - Type::Integer(IntegerType::I64), - Type::Integer(IntegerType::I128), - Type::Integer(IntegerType::U8), - Type::Integer(IntegerType::U16), - Type::Integer(IntegerType::U32), - Type::Integer(IntegerType::U64), - Type::Integer(IntegerType::U128), -]; - -const SIGNED_INT_TYPES: [Type; 5] = [ - Type::Integer(IntegerType::I8), - Type::Integer(IntegerType::I16), - Type::Integer(IntegerType::I32), - Type::Integer(IntegerType::I64), - Type::Integer(IntegerType::I128), -]; - -const UNSIGNED_INT_TYPES: [Type; 5] = [ - Type::Integer(IntegerType::U8), - Type::Integer(IntegerType::U16), - Type::Integer(IntegerType::U32), - Type::Integer(IntegerType::U64), - Type::Integer(IntegerType::U128), -]; - -const MAGNITUDE_TYPES: [Type; 3] = - [Type::Integer(IntegerType::U8), Type::Integer(IntegerType::U16), Type::Integer(IntegerType::U32)]; - impl<'a, N: Network> TypeChecker<'a, N> { /// Returns a new type checker given a symbol table and error handler. pub fn new(symbol_table: SymbolTable, type_table: &'a TypeTable, handler: &'a Handler) -> Self { @@ -153,15 +109,6 @@ impl<'a, N: Network> TypeChecker<'a, N> { self.handler.emit_warning(warning.into()); } - /// Emits an error to the handler if the given type is invalid. - fn check_type(&self, is_valid: impl Fn(&Type) -> bool, error_string: String, type_: &Option, span: Span) { - if let Some(type_) = type_ { - if !is_valid(type_) { - self.emit_err(TypeCheckerError::expected_one_type_of(error_string, type_, span)); - } - } - } - /// Emits an error if the two given types are not equal. pub(crate) fn check_eq_types(&self, t1: &Option, t2: &Option, span: Span) { match (t1, t2) { @@ -189,168 +136,83 @@ impl<'a, N: Network> TypeChecker<'a, N> { actual } - /// Emits an error to the error handler if the `actual` type is not equal to the `expected` type. - pub(crate) fn assert_type(&mut self, actual: &Option, expected: &Type, span: Span) { - if let Some(actual) = actual { - self.check_eq_types(&Some(actual.clone()), &Some(expected.clone()), span); + pub(crate) fn maybe_assert_type(&mut self, actual: &Type, expected: &Option, span: Span) { + if let Some(expected) = expected { + self.assert_type(actual, expected, span); } } - /// Emits an error to the error handler if the given type is not an address. - pub(crate) fn assert_address_type(&self, type_: &Option, span: Span) { - self.check_type(|type_: &Type| ADDRESS_TYPE.eq(type_), ADDRESS_TYPE.to_string(), type_, span) - } - - /// Emits an error to the handler if the given type is not a boolean. - pub(crate) fn assert_bool_type(&self, type_: &Option, span: Span) { - self.check_type(|type_: &Type| BOOLEAN_TYPE.eq(type_), BOOLEAN_TYPE.to_string(), type_, span) - } - - /// Emits an error to the handler if the given type is not a field. - pub(crate) fn assert_field_type(&self, type_: &Option, span: Span) { - self.check_type(|type_: &Type| FIELD_TYPE.eq(type_), FIELD_TYPE.to_string(), type_, span) - } - - /// Emits an error to the handler if the given type is not a group. - pub(crate) fn assert_group_type(&self, type_: &Option, span: Span) { - self.check_type(|type_: &Type| GROUP_TYPE.eq(type_), GROUP_TYPE.to_string(), type_, span) - } - - /// Emits an error to the handler if the given type is not a scalar. - pub(crate) fn assert_scalar_type(&self, type_: &Option, span: Span) { - self.check_type(|type_: &Type| SCALAR_TYPE.eq(type_), SCALAR_TYPE.to_string(), type_, span) - } - - /// Emits an error to the handler if the given type is not a signature. - pub(crate) fn assert_signature_type(&self, type_: &Option, span: Span) { - self.check_type(|type_: &Type| SIGNATURE_TYPE.eq(type_), SIGNATURE_TYPE.to_string(), type_, span) - } - - /// Emits an error to the handler if the given type is not an integer. - pub(crate) fn assert_int_type(&self, type_: &Option, span: Span) { - self.check_type(|type_: &Type| INT_TYPES.contains(type_), types_to_string(&INT_TYPES), type_, span) - } - - /// Emits an error to the handler if the given type is not a signed integer. - pub(crate) fn assert_signed_int_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| SIGNED_INT_TYPES.contains(type_), - types_to_string(&SIGNED_INT_TYPES), - type_, - span, - ) - } - - /// Emits an error to the handler if the given type is not an unsigned integer. - pub(crate) fn assert_unsigned_int_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| UNSIGNED_INT_TYPES.contains(type_), - types_to_string(&UNSIGNED_INT_TYPES), - type_, - span, - ) - } - - /// Emits an error to the handler if the given type is not a magnitude (u8, u16, u32). - pub(crate) fn assert_magnitude_type(&self, type_: &Option, span: Span) { - self.check_type(|type_: &Type| MAGNITUDE_TYPES.contains(type_), types_to_string(&MAGNITUDE_TYPES), type_, span) - } - - /// Emits an error to the handler if the given type is not a boolean or an integer. - pub(crate) fn assert_bool_int_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| BOOLEAN_TYPE.eq(type_) | INT_TYPES.contains(type_), - format!("{BOOLEAN_TYPE}, {}", types_to_string(&INT_TYPES)), - type_, - span, - ) - } - - /// Emits an error to the handler if the given type is not a field or integer. - pub(crate) fn assert_field_int_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| FIELD_TYPE.eq(type_) | INT_TYPES.contains(type_), - format!("{FIELD_TYPE}, {}", types_to_string(&INT_TYPES)), - type_, - span, - ) - } - - /// Emits an error to the handler if the given type is not a field or group. - pub(crate) fn assert_field_group_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| FIELD_TYPE.eq(type_) | GROUP_TYPE.eq(type_), - format!("{FIELD_TYPE}, {GROUP_TYPE}"), - type_, - span, - ) + pub(crate) fn assert_type(&mut self, actual: &Type, expected: &Type, span: Span) { + if actual != &Type::Err && !self.eq_user(actual, expected) { + // If `actual` is Err, we will have already reported an error. + self.emit_err(TypeCheckerError::type_should_be2(actual, format!("type `{expected}`"), span)); + } } - /// Emits an error to the handler if the given type is not a field, group, or integer. - pub(crate) fn assert_field_group_int_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| FIELD_TYPE.eq(type_) | GROUP_TYPE.eq(type_) | INT_TYPES.contains(type_), - format!("{FIELD_TYPE}, {GROUP_TYPE}, {}", types_to_string(&INT_TYPES),), - type_, - span, - ) + pub(crate) fn assert_int_type(&self, type_: &Type, span: Span) { + if !matches!(type_, Type::Err | Type::Integer(_)) { + self.emit_err(TypeCheckerError::type_should_be2(type_, "an integer", span)); + } } - /// Emits an error to the handler if the given type is not a field, group, or signed integer. - pub(crate) fn assert_field_group_signed_int_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| FIELD_TYPE.eq(type_) | GROUP_TYPE.eq(type_) | SIGNED_INT_TYPES.contains(type_), - format!("{FIELD_TYPE}, {GROUP_TYPE}, {}", types_to_string(&SIGNED_INT_TYPES),), + pub(crate) fn assert_unsigned_type(&self, type_: &Type, span: Span) { + if !matches!( type_, - span, - ) + Type::Err + | Type::Integer(IntegerType::U8) + | Type::Integer(IntegerType::U16) + | Type::Integer(IntegerType::U32) + | Type::Integer(IntegerType::U64) + | Type::Integer(IntegerType::U128) + ) { + self.emit_err(TypeCheckerError::type_should_be2(type_, "an unsigned integer", span)); + } } - /// Emits an error to the handler if the given type is not a field, scalar, or integer. - pub(crate) fn assert_field_scalar_int_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| FIELD_TYPE.eq(type_) | SCALAR_TYPE.eq(type_) | INT_TYPES.contains(type_), - format!("{FIELD_TYPE}, {SCALAR_TYPE}, {}", types_to_string(&INT_TYPES),), + pub(crate) fn assert_bool_int_type(&self, type_: &Type, span: Span) { + if !matches!( type_, - span, - ) + Type::Err + | Type::Boolean + | Type::Integer(IntegerType::U8) + | Type::Integer(IntegerType::U16) + | Type::Integer(IntegerType::U32) + | Type::Integer(IntegerType::U64) + | Type::Integer(IntegerType::U128) + | Type::Integer(IntegerType::I8) + | Type::Integer(IntegerType::I16) + | Type::Integer(IntegerType::I32) + | Type::Integer(IntegerType::I64) + | Type::Integer(IntegerType::I128) + ) { + self.emit_err(TypeCheckerError::type_should_be2(type_, "a bool or integer", span)); + } } - /// Emits an error to the handler if the given type is not a field, group, scalar, integer, or boolean. - pub(crate) fn assert_field_group_scalar_int_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| { - FIELD_TYPE.eq(type_) | GROUP_TYPE.eq(type_) | SCALAR_TYPE.eq(type_) | INT_TYPES.contains(type_) - }, - format!("{}, {}, {}, {}", FIELD_TYPE, GROUP_TYPE, SCALAR_TYPE, types_to_string(&INT_TYPES),), + pub(crate) fn assert_field_int_type(&self, type_: &Type, span: Span) { + if !matches!( type_, - span, - ) + Type::Err + | Type::Field + | Type::Integer(IntegerType::U8) + | Type::Integer(IntegerType::U16) + | Type::Integer(IntegerType::U32) + | Type::Integer(IntegerType::U64) + | Type::Integer(IntegerType::U128) + | Type::Integer(IntegerType::I8) + | Type::Integer(IntegerType::I16) + | Type::Integer(IntegerType::I32) + | Type::Integer(IntegerType::I64) + | Type::Integer(IntegerType::I128) + ) { + self.emit_err(TypeCheckerError::type_should_be2(type_, "a field or integer", span)); + } } - /// Emits an error to the handler if the given type is not a field, group, scalar, integer, boolean, or address. - pub(crate) fn assert_castable_type(&self, type_: &Option, span: Span) { - self.check_type( - |type_: &Type| { - FIELD_TYPE.eq(type_) - | GROUP_TYPE.eq(type_) - | SCALAR_TYPE.eq(type_) - | INT_TYPES.contains(type_) - | BOOLEAN_TYPE.eq(type_) - | ADDRESS_TYPE.eq(type_) - }, - format!( - "{}, {}, {}, {}, {}, {}", - FIELD_TYPE, - GROUP_TYPE, - SCALAR_TYPE, - types_to_string(&INT_TYPES), - BOOLEAN_TYPE, - ADDRESS_TYPE - ), - type_, - span, - ) + pub(crate) fn assert_field_group_int_type(&self, type_: &Type, span: Span) { + if !matches!(type_, Type::Err | Type::Field | Type::Group | Type::Integer(_)) { + self.emit_err(TypeCheckerError::type_should_be2(type_, "a field, group, or integer", span)); + } } /// Type checks the inputs to an associated constant and returns the expected output type. @@ -388,9 +250,9 @@ impl<'a, N: Network> TypeChecker<'a, N> { pub(crate) fn check_core_function_call( &mut self, core_function: CoreFunction, - arguments: &[(Option, Span)], + arguments: &[(Type, Span)], function_span: Span, - ) -> Option { + ) -> Type { // Check that the number of arguments is correct. if arguments.len() != core_function.num_args() { self.emit_err(TypeCheckerError::incorrect_num_args_to_call( @@ -398,61 +260,60 @@ impl<'a, N: Network> TypeChecker<'a, N> { arguments.len(), function_span, )); - return None; + return Type::Err; } - // Helper to check that the type of argument is not a mapping, tuple, err, or unit type. - let check_not_mapping_tuple_err_unit = |type_: &Option, span: &Span| { - self.check_type( - |type_: &Type| !matches!(type_, Type::Mapping(_) | Type::Tuple(_) | Type::Err | Type::Unit), - "address, bool, field, group, struct, integer, scalar, struct".to_string(), - type_, - *span, - ); + let assert_not_mapping_tuple_unit = |type_: &Type, span: Span| { + if matches!(type_, Type::Mapping(_) | Type::Tuple(_) | Type::Unit) { + self.emit_err(TypeCheckerError::type_should_be(type_, "anything but a mapping, tuple, or unit", span)); + } }; - // Helper to check that the type of the argument is a valid input to a Pedersen hash/commit with 64-bit inputs. - // The console types in snarkVM have some overhead in their bitwise representation. Consequently, Pedersen64 cannot accept a u64. - let check_pedersen_64_bit_input = |type_: &Option, span: &Span| { - self.check_type( - |type_: &Type| { - !matches!( - type_, - Type::Integer(IntegerType::U64) - | Type::Integer(IntegerType::I64) - | Type::Integer(IntegerType::U128) - | Type::Integer(IntegerType::I128) - | Type::Mapping(_) - | Type::Tuple(_) - | Type::Err - | Type::Unit - ) - }, - "address, bool, field, group, struct, integer, scalar, struct".to_string(), + // Make sure the input is no bigger than 64 bits. + // Due to overhead in the bitwise representations of types in SnarkVM, 64 bit integers + // input more than 64 bits to a hash function. + let assert_pedersen_64_bit_input = |type_: &Type, span: Span| { + if !matches!( type_, - *span, - ); + Type::Integer(IntegerType::U8) + | Type::Integer(IntegerType::U16) + | Type::Integer(IntegerType::U32) + | Type::Integer(IntegerType::I8) + | Type::Integer(IntegerType::I16) + | Type::Integer(IntegerType::I32) + | Type::Boolean + | Type::Err + ) { + self.emit_err(TypeCheckerError::type_should_be( + type_, + "an integer of less than 64 bits or a bool", + span, + )); + } }; - // Helper to check that the type of the argument is a valid input to a Pedersen hash/commit with 128-bit inputs. - // The console types in snarkVM have some overhead in their bitwise representation. Consequently, Pedersen128 cannot accept a u128. - let check_pedersen_128_bit_input = |type_: &Option, span: &Span| { - self.check_type( - |type_: &Type| { - !matches!( - type_, - Type::Integer(IntegerType::U128) - | Type::Integer(IntegerType::I128) - | Type::Mapping(_) - | Type::Tuple(_) - | Type::Err - | Type::Unit - ) - }, - "address, bool, field, group, struct, integer, scalar, struct".to_string(), + // Make sure the input is no bigger than 128 bits. + let assert_pedersen_128_bit_input = |type_: &Type, span: Span| { + // This is presumably a little more conservative than necessary. + if !matches!( type_, - *span, - ); + Type::Integer(IntegerType::U8) + | Type::Integer(IntegerType::U16) + | Type::Integer(IntegerType::U32) + | Type::Integer(IntegerType::U64) + | Type::Integer(IntegerType::I8) + | Type::Integer(IntegerType::I16) + | Type::Integer(IntegerType::I32) + | Type::Integer(IntegerType::I64) + | Type::Boolean + | Type::Err + ) { + self.emit_err(TypeCheckerError::type_should_be( + type_, + "an integer of less than 128 bits or a bool", + span, + )); + } }; // Check that the arguments are of the correct type. @@ -461,31 +322,25 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::BHP512CommitToAddress | CoreFunction::BHP768CommitToAddress | CoreFunction::BHP1024CommitToAddress => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - // Check that the second argument is a scalar. - self.assert_scalar_type(&arguments[1].0, arguments[1].1); - Some(Type::Address) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + self.assert_type(&arguments[1].0, &Type::Scalar, arguments[1].1); + Type::Address } CoreFunction::BHP256CommitToField | CoreFunction::BHP512CommitToField | CoreFunction::BHP768CommitToField | CoreFunction::BHP1024CommitToField => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - // Check that the second argument is a scalar. - self.assert_scalar_type(&arguments[1].0, arguments[1].1); - Some(Type::Field) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + self.assert_type(&arguments[1].0, &Type::Scalar, arguments[1].1); + Type::Field } CoreFunction::BHP256CommitToGroup | CoreFunction::BHP512CommitToGroup | CoreFunction::BHP768CommitToGroup | CoreFunction::BHP1024CommitToGroup => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - // Check that the second argument is a scalar. - self.assert_scalar_type(&arguments[1].0, arguments[1].1); - Some(Type::Group) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + self.assert_type(&arguments[1].0, &Type::Scalar, arguments[1].1); + Type::Group } CoreFunction::BHP256HashToAddress | CoreFunction::BHP512HashToAddress @@ -500,9 +355,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToAddress | CoreFunction::SHA3_384HashToAddress | CoreFunction::SHA3_512HashToAddress => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Address) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Address } CoreFunction::BHP256HashToField | CoreFunction::BHP512HashToField @@ -517,9 +371,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToField | CoreFunction::SHA3_384HashToField | CoreFunction::SHA3_512HashToField => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Field) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Field } CoreFunction::BHP256HashToGroup | CoreFunction::BHP512HashToGroup @@ -534,9 +387,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToGroup | CoreFunction::SHA3_384HashToGroup | CoreFunction::SHA3_512HashToGroup => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Group) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Group } CoreFunction::BHP256HashToI8 | CoreFunction::BHP512HashToI8 @@ -551,9 +403,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToI8 | CoreFunction::SHA3_384HashToI8 | CoreFunction::SHA3_512HashToI8 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I8)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I8) } CoreFunction::BHP256HashToI16 | CoreFunction::BHP512HashToI16 @@ -568,9 +419,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToI16 | CoreFunction::SHA3_384HashToI16 | CoreFunction::SHA3_512HashToI16 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I16)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I16) } CoreFunction::BHP256HashToI32 | CoreFunction::BHP512HashToI32 @@ -585,9 +435,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToI32 | CoreFunction::SHA3_384HashToI32 | CoreFunction::SHA3_512HashToI32 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I32)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I32) } CoreFunction::BHP256HashToI64 | CoreFunction::BHP512HashToI64 @@ -602,9 +451,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToI64 | CoreFunction::SHA3_384HashToI64 | CoreFunction::SHA3_512HashToI64 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I64)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I64) } CoreFunction::BHP256HashToI128 | CoreFunction::BHP512HashToI128 @@ -619,9 +467,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToI128 | CoreFunction::SHA3_384HashToI128 | CoreFunction::SHA3_512HashToI128 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I128)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I128) } CoreFunction::BHP256HashToU8 | CoreFunction::BHP512HashToU8 @@ -636,9 +483,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToU8 | CoreFunction::SHA3_384HashToU8 | CoreFunction::SHA3_512HashToU8 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U8)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U8) } CoreFunction::BHP256HashToU16 | CoreFunction::BHP512HashToU16 @@ -653,9 +499,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToU16 | CoreFunction::SHA3_384HashToU16 | CoreFunction::SHA3_512HashToU16 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U16)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U16) } CoreFunction::BHP256HashToU32 | CoreFunction::BHP512HashToU32 @@ -670,9 +515,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToU32 | CoreFunction::SHA3_384HashToU32 | CoreFunction::SHA3_512HashToU32 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U32)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U32) } CoreFunction::BHP256HashToU64 | CoreFunction::BHP512HashToU64 @@ -687,9 +531,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToU64 | CoreFunction::SHA3_384HashToU64 | CoreFunction::SHA3_512HashToU64 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U64)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U64) } CoreFunction::BHP256HashToU128 | CoreFunction::BHP512HashToU128 @@ -704,9 +547,8 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToU128 | CoreFunction::SHA3_384HashToU128 | CoreFunction::SHA3_512HashToU128 => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U128)) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U128) } CoreFunction::BHP256HashToScalar | CoreFunction::BHP512HashToScalar @@ -721,321 +563,290 @@ impl<'a, N: Network> TypeChecker<'a, N> { | CoreFunction::SHA3_256HashToScalar | CoreFunction::SHA3_384HashToScalar | CoreFunction::SHA3_512HashToScalar => { - // Check that the first argument is not a mapping, tuple, err, or unit type. - check_not_mapping_tuple_err_unit(&arguments[0].0, &arguments[0].1); - Some(Type::Scalar) + assert_not_mapping_tuple_unit(&arguments[0].0, arguments[0].1); + Type::Scalar } CoreFunction::Pedersen64CommitToAddress => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); // Check that the second argument is a scalar. - self.assert_scalar_type(&arguments[1].0, arguments[1].1); - - Some(Type::Address) + self.assert_type(&arguments[1].0, &Type::Scalar, arguments[1].1); + Type::Address } CoreFunction::Pedersen64CommitToField => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); // Check that the second argument is a scalar. - self.assert_scalar_type(&arguments[1].0, arguments[1].1); - - Some(Type::Field) + self.assert_type(&arguments[1].0, &Type::Scalar, arguments[1].1); + Type::Field } CoreFunction::Pedersen64CommitToGroup => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); // Check that the second argument is a scalar. - self.assert_scalar_type(&arguments[1].0, arguments[1].1); - - Some(Type::Group) + self.assert_type(&arguments[1].0, &Type::Scalar, arguments[1].1); + Type::Group } CoreFunction::Pedersen64HashToAddress => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Address) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Address } CoreFunction::Pedersen64HashToField => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Field) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Field } CoreFunction::Pedersen64HashToGroup => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Group) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Group } CoreFunction::Pedersen64HashToI8 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I8)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I8) } CoreFunction::Pedersen64HashToI16 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I16)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I16) } CoreFunction::Pedersen64HashToI32 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I32)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I32) } CoreFunction::Pedersen64HashToI64 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I64)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I64) } CoreFunction::Pedersen64HashToI128 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I128)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I128) } CoreFunction::Pedersen64HashToU8 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U8)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U8) } CoreFunction::Pedersen64HashToU16 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U16)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U16) } CoreFunction::Pedersen64HashToU32 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U32)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U32) } CoreFunction::Pedersen64HashToU64 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U64)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U64) } CoreFunction::Pedersen64HashToU128 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U128)) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U128) } CoreFunction::Pedersen64HashToScalar => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 32 bits. - check_pedersen_64_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Scalar) + assert_pedersen_64_bit_input(&arguments[0].0, arguments[0].1); + Type::Scalar } CoreFunction::Pedersen128CommitToAddress => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - // Check that the second argument is a scalar. - self.assert_scalar_type(&arguments[1].0, arguments[1].1); - - Some(Type::Address) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + self.assert_type(&arguments[1].0, &Type::Scalar, arguments[1].1); + Type::Address } CoreFunction::Pedersen128CommitToField => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - // Check that the second argument is a scalar. - self.assert_scalar_type(&arguments[1].0, arguments[1].1); - - Some(Type::Field) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + self.assert_type(&arguments[1].0, &Type::Scalar, arguments[1].1); + Type::Field } CoreFunction::Pedersen128CommitToGroup => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - // Check that the second argument is a scalar. - self.assert_scalar_type(&arguments[1].0, arguments[1].1); - - Some(Type::Group) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + self.assert_type(&arguments[1].0, &Type::Scalar, arguments[1].1); + Type::Group } CoreFunction::Pedersen128HashToAddress => { // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Address) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Address } CoreFunction::Pedersen128HashToField => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Field) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Field } CoreFunction::Pedersen128HashToGroup => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Group) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Group } CoreFunction::Pedersen128HashToI8 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I8)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I8) } CoreFunction::Pedersen128HashToI16 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I16)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I16) } CoreFunction::Pedersen128HashToI32 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I32)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I32) } CoreFunction::Pedersen128HashToI64 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I64)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I64) } CoreFunction::Pedersen128HashToI128 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::I128)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::I128) } CoreFunction::Pedersen128HashToU8 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U8)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U8) } CoreFunction::Pedersen128HashToU16 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U16)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U16) } CoreFunction::Pedersen128HashToU32 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U32)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U32) } CoreFunction::Pedersen128HashToU64 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U64)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U64) } CoreFunction::Pedersen128HashToU128 => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Integer(IntegerType::U128)) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Integer(IntegerType::U128) } CoreFunction::Pedersen128HashToScalar => { - // Check that the first argument is not a mapping, tuple, err, unit type, or integer over 64 bits. - check_pedersen_128_bit_input(&arguments[0].0, &arguments[0].1); - Some(Type::Scalar) + assert_pedersen_128_bit_input(&arguments[0].0, arguments[0].1); + Type::Scalar } CoreFunction::MappingGet => { // Check that the operation is invoked in a `finalize` block. self.check_access_allowed("Mapping::get", true, function_span); // Check that the first argument is a mapping. - if let Some(mapping_type) = self.assert_mapping_type(&arguments[0].0, arguments[0].1) { - // Check that the second argument matches the key type of the mapping. - self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); - // Return the value type of the mapping. - Some(*mapping_type.value) - } else { - None - } + self.assert_mapping_type(&arguments[0].0, arguments[0].1); + let Type::Mapping(mapping_type) = &arguments[0].0 else { + // We will have already handled the error in the assertion. + return Type::Err; + }; + + self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); + + mapping_type.value.deref().clone() } CoreFunction::MappingGetOrUse => { // Check that the operation is invoked in a `finalize` block. self.check_access_allowed("Mapping::get_or", true, function_span); // Check that the first argument is a mapping. - if let Some(mapping_type) = self.assert_mapping_type(&arguments[0].0, arguments[0].1) { - // Check that the second argument matches the key type of the mapping. - self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); - // Check that the third argument matches the value type of the mapping. - self.assert_type(&arguments[2].0, &mapping_type.value, arguments[2].1); - // Return the value type of the mapping. - Some(*mapping_type.value) - } else { - None - } + self.assert_mapping_type(&arguments[0].0, arguments[0].1); + + let Type::Mapping(mapping_type) = &arguments[0].0 else { + // We will have already handled the error in the assertion. + return Type::Err; + }; + + // Check that the second argument matches the key type of the mapping. + self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); + // Check that the third argument matches the value type of the mapping. + self.assert_type(&arguments[2].0, &mapping_type.value, arguments[2].1); + + mapping_type.value.deref().clone() } CoreFunction::MappingSet => { // Check that the operation is invoked in a `finalize` block. self.check_access_allowed("Mapping::set", true, function_span); // Check that the first argument is a mapping. - if let Some(mapping_type) = self.assert_mapping_type(&arguments[0].0, arguments[0].1) { - // Cannot modify external mappings. - if mapping_type.program != self.scope_state.program_name.unwrap() { - self.handler.emit_err(TypeCheckerError::cannot_modify_external_mapping("set", function_span)); - } - // Check that the second argument matches the key type of the mapping. - self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); - // Check that the third argument matches the value type of the mapping. - self.assert_type(&arguments[2].0, &mapping_type.value, arguments[2].1); - // Return the mapping type. - Some(Type::Unit) - } else { - None - } + self.assert_mapping_type(&arguments[0].0, arguments[0].1); + + let Type::Mapping(mapping_type) = &arguments[0].0 else { + // We will have already handled the error in the assertion. + return Type::Err; + }; + + // Check that the second argument matches the key type of the mapping. + self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); + // Check that the third argument matches the value type of the mapping. + self.assert_type(&arguments[2].0, &mapping_type.value, arguments[2].1); + + Type::Unit } CoreFunction::MappingRemove => { // Check that the operation is invoked in a `finalize` block. self.check_access_allowed("Mapping::remove", true, function_span); // Check that the first argument is a mapping. - if let Some(mapping_type) = self.assert_mapping_type(&arguments[0].0, arguments[0].1) { - // Cannot modify external mappings. - if mapping_type.program != self.scope_state.program_name.unwrap() { - self.handler - .emit_err(TypeCheckerError::cannot_modify_external_mapping("remove", function_span)); - } - // Check that the second argument matches the key type of the mapping. - self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); - // Return nothing. - Some(Type::Unit) - } else { - None + self.assert_mapping_type(&arguments[0].0, arguments[0].1); + + let Type::Mapping(mapping_type) = &arguments[0].0 else { + // We will have already handled the error in the assertion. + return Type::Err; + }; + + // Cannot modify external mappings. + if mapping_type.program != self.scope_state.program_name.unwrap() { + self.handler.emit_err(TypeCheckerError::cannot_modify_external_mapping("remove", function_span)); } + + // Check that the second argument matches the key type of the mapping. + self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); + + Type::Unit } CoreFunction::MappingContains => { // Check that the operation is invoked in a `finalize` block. - self.check_access_allowed("Mapping::contains", true, function_span); + self.check_access_allowed("Mapping::remove", true, function_span); // Check that the first argument is a mapping. - if let Some(mapping_type) = self.assert_mapping_type(&arguments[0].0, arguments[0].1) { - // Check that the second argument matches the key type of the mapping. - self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); - // Return a boolean. - Some(Type::Boolean) - } else { - None + self.assert_mapping_type(&arguments[0].0, arguments[0].1); + + let Type::Mapping(mapping_type) = &arguments[0].0 else { + // We will have already handled the error in the assertion. + return Type::Err; + }; + + // Cannot modify external mappings. + if mapping_type.program != self.scope_state.program_name.unwrap() { + self.handler.emit_err(TypeCheckerError::cannot_modify_external_mapping("remove", function_span)); } + + // Check that the second argument matches the key type of the mapping. + self.assert_type(&arguments[1].0, &mapping_type.key, arguments[1].1); + + Type::Boolean } CoreFunction::GroupToXCoordinate | CoreFunction::GroupToYCoordinate => { // Check that the first argument is a group. - self.assert_group_type(&arguments[0].0, arguments[0].1); - Some(Type::Field) - } - CoreFunction::ChaChaRandAddress => Some(Type::Address), - CoreFunction::ChaChaRandBool => Some(Type::Boolean), - CoreFunction::ChaChaRandField => Some(Type::Field), - CoreFunction::ChaChaRandGroup => Some(Type::Group), - CoreFunction::ChaChaRandI8 => Some(Type::Integer(IntegerType::I8)), - CoreFunction::ChaChaRandI16 => Some(Type::Integer(IntegerType::I16)), - CoreFunction::ChaChaRandI32 => Some(Type::Integer(IntegerType::I32)), - CoreFunction::ChaChaRandI64 => Some(Type::Integer(IntegerType::I64)), - CoreFunction::ChaChaRandI128 => Some(Type::Integer(IntegerType::I128)), - CoreFunction::ChaChaRandScalar => Some(Type::Scalar), - CoreFunction::ChaChaRandU8 => Some(Type::Integer(IntegerType::U8)), - CoreFunction::ChaChaRandU16 => Some(Type::Integer(IntegerType::U16)), - CoreFunction::ChaChaRandU32 => Some(Type::Integer(IntegerType::U32)), - CoreFunction::ChaChaRandU64 => Some(Type::Integer(IntegerType::U64)), - CoreFunction::ChaChaRandU128 => Some(Type::Integer(IntegerType::U128)), + self.assert_type(&arguments[0].0, &Type::Group, arguments[0].1); + Type::Field + } + CoreFunction::ChaChaRandAddress => Type::Address, + CoreFunction::ChaChaRandBool => Type::Boolean, + CoreFunction::ChaChaRandField => Type::Field, + CoreFunction::ChaChaRandGroup => Type::Group, + CoreFunction::ChaChaRandI8 => Type::Integer(IntegerType::I8), + CoreFunction::ChaChaRandI16 => Type::Integer(IntegerType::I16), + CoreFunction::ChaChaRandI32 => Type::Integer(IntegerType::I32), + CoreFunction::ChaChaRandI64 => Type::Integer(IntegerType::I64), + CoreFunction::ChaChaRandI128 => Type::Integer(IntegerType::I128), + CoreFunction::ChaChaRandScalar => Type::Scalar, + CoreFunction::ChaChaRandU8 => Type::Integer(IntegerType::U8), + CoreFunction::ChaChaRandU16 => Type::Integer(IntegerType::U16), + CoreFunction::ChaChaRandU32 => Type::Integer(IntegerType::U32), + CoreFunction::ChaChaRandU64 => Type::Integer(IntegerType::U64), + CoreFunction::ChaChaRandU128 => Type::Integer(IntegerType::U128), CoreFunction::SignatureVerify => { // Check that the first argument is a signature. - self.assert_signature_type(&arguments[0].0, arguments[0].1); + self.assert_type(&arguments[0].0, &Type::Signature, arguments[0].1); // Check that the second argument is an address. - self.assert_address_type(&arguments[1].0, arguments[1].1); - // Return a boolean. - Some(Type::Boolean) + self.assert_type(&arguments[1].0, &Type::Address, arguments[1].1); + Type::Boolean } - CoreFunction::FutureAwait => Some(Type::Unit), + CoreFunction::FutureAwait => Type::Unit, CoreFunction::CheatCodePrintMapping => { - // Check that the argument is a mapping. - let _ = self.assert_mapping_type(&arguments[0].0, arguments[0].1); - Some(Type::Unit) + self.assert_mapping_type(&arguments[0].0, arguments[0].1); + Type::Unit } CoreFunction::CheatCodeSetBlockHeight => { - // Assert that the argument is a u32. self.assert_type(&arguments[0].0, &Type::Integer(IntegerType::U32), arguments[0].1); - Some(Type::Unit) + Type::Unit } } } /// Returns the `struct` type and emits an error if the `expected` type does not match. pub(crate) fn check_expected_struct(&mut self, struct_: &Composite, expected: &Option, span: Span) -> Type { - let current_struct = CompositeType { id: struct_.identifier, program: struct_.external }; + let program = struct_.external.or(self.scope_state.program_name); + let current_struct = CompositeType { id: struct_.identifier, program }; if expected.is_some() { self.check_eq_types(&Some(Type::Composite(current_struct)), expected, span); } @@ -1121,17 +932,16 @@ impl<'a, N: Network> TypeChecker<'a, N> { } /// Emits an error if the type is not a mapping. - pub(crate) fn assert_mapping_type(&self, type_: &Option, span: Span) -> Option { - self.check_type(|type_| matches!(type_, Type::Mapping(_)), "mapping".to_string(), type_, span); - match type_ { - Some(Type::Mapping(mapping_type)) => Some(mapping_type.clone()), - _ => None, + pub(crate) fn assert_mapping_type(&self, type_: &Type, span: Span) { + if type_ != &Type::Err && !matches!(type_, Type::Mapping(_)) { + self.emit_err(TypeCheckerError::type_should_be2(type_, "a mapping", span)); } } - /// Emits an error if the type is not an array. - pub(crate) fn assert_array_type(&self, type_: &Option, span: Span) { - self.check_type(|type_| matches!(type_, Type::Array(_)), "array".to_string(), type_, span); + pub(crate) fn assert_array_type(&self, type_: &Type, span: Span) { + if type_ != &Type::Err && !matches!(type_, Type::Array(_)) { + self.emit_err(TypeCheckerError::type_should_be2(type_, "an array", span)); + } } /// Helper function to check that the input and output of function are valid @@ -1308,6 +1118,51 @@ impl<'a, N: Network> TypeChecker<'a, N> { }); } + pub(crate) fn eq_user(&self, t1: &Type, t2: &Type) -> bool { + match (t1, t2) { + (Type::Err, _) + | (_, Type::Err) + | (Type::Address, Type::Address) + | (Type::Boolean, Type::Boolean) + | (Type::Field, Type::Field) + | (Type::Group, Type::Group) + | (Type::Scalar, Type::Scalar) + | (Type::Signature, Type::Signature) + | (Type::String, Type::String) + | (Type::Unit, Type::Unit) => true, + (Type::Array(left), Type::Array(right)) => { + left.length() == right.length() && self.eq_user(left.element_type(), right.element_type()) + } + (Type::Identifier(left), Type::Identifier(right)) => left.name == right.name, + (Type::Integer(left), Type::Integer(right)) => left == right, + (Type::Mapping(left), Type::Mapping(right)) => { + self.eq_user(&left.key, &right.key) && self.eq_user(&left.value, &right.value) + } + (Type::Tuple(left), Type::Tuple(right)) if left.length() == right.length() => left + .elements() + .iter() + .zip_eq(right.elements().iter()) + .all(|(left_type, right_type)| self.eq_user(left_type, right_type)), + (Type::Composite(left), Type::Composite(right)) => { + if left.id.name != right.id.name { + return false; + } + + let left_program = left.program.or(self.scope_state.program_name); + let right_program = right.program.or(self.scope_state.program_name); + + left_program == right_program + } + (Type::Future(left), Type::Future(right)) if !left.is_explicit || !right.is_explicit => true, + (Type::Future(left), Type::Future(right)) if left.inputs.len() == right.inputs.len() => left + .inputs() + .iter() + .zip_eq(right.inputs().iter()) + .all(|(left_type, right_type)| self.eq_user(left_type, right_type)), + _ => false, + } + } + /// Wrapper around lookup_struct that additionally records all structs that are used in the program. pub(crate) fn lookup_struct(&mut self, program: Option, name: Symbol) -> Option { let struct_ = self @@ -1360,7 +1215,3 @@ impl<'a, N: Network> TypeChecker<'a, N> { } } } - -fn types_to_string(types: &[Type]) -> String { - types.iter().map(|type_| type_.to_string()).join(", ") -} diff --git a/errors/src/errors/type_checker/type_checker_error.rs b/errors/src/errors/type_checker/type_checker_error.rs index 1ec82fc902..66279fefc9 100644 --- a/errors/src/errors/type_checker/type_checker_error.rs +++ b/errors/src/errors/type_checker/type_checker_error.rs @@ -819,8 +819,8 @@ create_messages!( @formatted external_transition_call_must_be_before_finalize { args: (), - msg: "External async transition calls cannot be made after local async function call".to_string(), - help: Some("Move the async call before the function call.".to_string()), + msg: "External transition calls cannot be made after local async function call".to_string(), + help: Some("Move the async function call before the transition call.".to_string()), } @formatted @@ -919,4 +919,59 @@ create_messages!( msg: format!("Futures may only appear as parameters to async functions."), help: None, } + + /// For when the user tries to assign to a const input. + @formatted + type_should_be2 { + args: (type_: impl Display, expected: impl Display), + msg: format!( + "Expected {expected} but type `{type_}` was found.", + ), + help: None, + } + + @formatted + ternary_branch_mismatch { + args: (type1: impl Display, type2: impl Display), + msg: format!( + "Received different types `{type1}` and `{type2}` for the arms of a ternary conditional." + ), + help: Some("Make both branches the same type.".into()), + } + + @formatted + operation_types_mismatch { + args: (operation: impl Display, type1: impl Display, type2: impl Display), + msg: format!( + "Received different types `{type1}` and `{type2}` for the operation `{operation}`." + ), + help: Some("Make both operands the same type.".into()), + } + + @formatted + mul_types_mismatch { + args: (type1: impl Display, type2: impl Display), + msg: format!( + "Received types `{type1}` and `{type2}` for the operation `*`." + ), + help: Some("Valid operands are two integers of the same type, two fields, or a scalar and a group.".into()), + } + + @formatted + pow_types_mismatch { + args: (type1: impl Display, type2: impl Display), + msg: format!( + "Received types `{type1}` and `{type2}` for the operation `pow`." + ), + help: Some("Valid operands are two fields, or an integer base and a `u8`, `u16`, or `u32` exponent.".into()), + } + + @formatted + shift_type_magnitude { + args: (operation: impl Display, rhs_type: impl Display), + msg: format!( + "Received type `{rhs_type}` for the second operand of the operation `{operation}`." + ), + help: Some("Valid second operands are `u8`, `u16`, or `u32`".into()), + } ); diff --git a/tests/expectations/compiler/address/gt_fail.out b/tests/expectations/compiler/address/gt_fail.out index ddcedee123..e80958e725 100644 --- a/tests/expectations/compiler/address/gt_fail.out +++ b/tests/expectations/compiler/address/gt_fail.out @@ -1,11 +1,16 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372021]: Comparison `>` is not supported for the address type. +Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found. --> compiler-test:7:16 | 7 | return x > sender; - | ^^^^^^^^^^ + | ^ +Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found. + --> compiler-test:7:20 + | + 7 | return x > sender; + | ^^^^^^ Error [ETYC0372083]: A program must have at least one transition function. --> compiler-test:1:1 | diff --git a/tests/expectations/compiler/address/gte_fail.out b/tests/expectations/compiler/address/gte_fail.out index a1091337ef..a7c03690b9 100644 --- a/tests/expectations/compiler/address/gte_fail.out +++ b/tests/expectations/compiler/address/gte_fail.out @@ -1,11 +1,16 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372021]: Comparison `>=` is not supported for the address type. +Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found. --> compiler-test:7:16 | 7 | return x >= sender; - | ^^^^^^^^^^^ + | ^ +Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found. + --> compiler-test:7:21 + | + 7 | return x >= sender; + | ^^^^^^ Error [ETYC0372083]: A program must have at least one transition function. --> compiler-test:1:1 | diff --git a/tests/expectations/compiler/address/lt_fail.out b/tests/expectations/compiler/address/lt_fail.out index 401cadb145..b7e0fd415b 100644 --- a/tests/expectations/compiler/address/lt_fail.out +++ b/tests/expectations/compiler/address/lt_fail.out @@ -1,11 +1,16 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372021]: Comparison `<` is not supported for the address type. +Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found. --> compiler-test:7:16 | 7 | return x < sender; - | ^^^^^^^^^^ + | ^ +Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found. + --> compiler-test:7:20 + | + 7 | return x < sender; + | ^^^^^^ Error [ETYC0372083]: A program must have at least one transition function. --> compiler-test:1:1 | diff --git a/tests/expectations/compiler/address/lte_fail.out b/tests/expectations/compiler/address/lte_fail.out index 14995496f0..6d9f8f8379 100644 --- a/tests/expectations/compiler/address/lte_fail.out +++ b/tests/expectations/compiler/address/lte_fail.out @@ -1,11 +1,16 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372021]: Comparison `<=` is not supported for the address type. +Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found. --> compiler-test:7:16 | 7 | return x <= sender; - | ^^^^^^^^^^^ + | ^ +Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found. + --> compiler-test:7:21 + | + 7 | return x <= sender; + | ^^^^^^ Error [ETYC0372083]: A program must have at least one transition function. --> compiler-test:1:1 | diff --git a/tests/expectations/compiler/array/array_initialization_fail.out b/tests/expectations/compiler/array/array_initialization_fail.out index 4b64140084..831805c8ac 100644 --- a/tests/expectations/compiler/array/array_initialization_fail.out +++ b/tests/expectations/compiler/array/array_initialization_fail.out @@ -1,12 +1,12 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `[bool; 8]` but type `[bool; 7]` was found +Error [ETYC0372117]: Expected type `[bool; 8]` but type `[bool; 7]` was found. --> compiler-test:5:16 | 5 | return [a, a, a, a, a, a, a]; | ^^^^^^^^^^^^^^^^^^^^^ -Error [ETYC0372003]: Expected type `u8` but type `u32` was found +Error [ETYC0372117]: Expected type `u8` but type `u32` was found. --> compiler-test:9:52 | 9 | return [1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u32]; diff --git a/tests/expectations/compiler/array/nested_array_sum_fail.out b/tests/expectations/compiler/array/nested_array_sum_fail.out index 84d1bf3388..1ac4eab89c 100644 --- a/tests/expectations/compiler/array/nested_array_sum_fail.out +++ b/tests/expectations/compiler/array/nested_array_sum_fail.out @@ -1,14 +1,9 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372007]: Expected one type from `array`, but got `u32` +Error [ETYC0372117]: Expected an array but type `u32` was found. --> compiler-test:9:29 | 9 | sum = sum + a[i][j]; | ^^^^ -Error [ETYC0372003]: Expected type `u32` but type `no type` was found - --> compiler-test:9:23 - | - 9 | sum = sum + a[i][j]; - | ^^^^^^^^^^^^^ """] diff --git a/tests/expectations/compiler/constants/block_height_type_fail.out b/tests/expectations/compiler/constants/block_height_type_fail.out index fcb4df4d49..ca2f04e81c 100644 --- a/tests/expectations/compiler/constants/block_height_type_fail.out +++ b/tests/expectations/compiler/constants/block_height_type_fail.out @@ -1,7 +1,7 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `u64` but type `u32` was found +Error [ETYC0372117]: Expected type `u64` but type `u32` was found. --> compiler-test:5:22 | 5 | let x: u64 = block.height; diff --git a/tests/expectations/compiler/constants/constant_loop_bound_type_mismatch_fail.out b/tests/expectations/compiler/constants/constant_loop_bound_type_mismatch_fail.out index 45076ec730..e1632090c0 100644 --- a/tests/expectations/compiler/constants/constant_loop_bound_type_mismatch_fail.out +++ b/tests/expectations/compiler/constants/constant_loop_bound_type_mismatch_fail.out @@ -1,7 +1,7 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `u8` but type `u32` was found +Error [ETYC0372117]: Expected type `u8` but type `u32` was found. --> compiler-test:8:22 | 8 | for i: u8 in START..STOP { diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i128.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i128.out index f315c6c5ef..56deb375fa 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i128.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i128.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "43b6979d03d85a3d64bfdd50fda155faf201deb4cf96b11b4b8f2c17a1185beb", type_checked_symbol_table = "f97ccf5d4b99cf0b05d41ba235ad8681c4126ec0b766186aa710f3d081c702cd", unrolled_symbol_table = "f97ccf5d4b99cf0b05d41ba235ad8681c4126ec0b766186aa710f3d081c702cd", initial_ast = "bf89bff0fb684a62a32bf1b3a3354dc9253672fab0e0458323a6e0ee27a1c43f", unrolled_ast = "bf89bff0fb684a62a32bf1b3a3354dc9253672fab0e0458323a6e0ee27a1c43f", ssa_ast = "f224b430ca2db6b408ac8f72fd96cad85f1644854bf86cd05fe904a2b8a427d4", flattened_ast = "64643c25ca0e537611e5381340feb1754b72e31b0efaf837b8354a491b3a59cc", destructured_ast = "3aabc428bd9afe0b5b9f005287cc0389d1a81603be2f72403f30ed566f0f3611", inlined_ast = "3aabc428bd9afe0b5b9f005287cc0389d1a81603be2f72403f30ed566f0f3611", dce_ast = "e709d068f653888369009929a437ac5b7a424677702dd3ab30e7c3a790e35dfc", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i128; - output r8 as i128.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:49 + | + 27 | let a: i128 = Pedersen128::hash_to_i128(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:49 + | + 29 | let c: i128 = Pedersen128::hash_to_i128(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:49 + | + 30 | let d: i128 = Pedersen128::hash_to_i128(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:49 + | + 39 | let o: i128 = Pedersen128::hash_to_i128(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:49 + | + 41 | let q: i128 = Pedersen128::hash_to_i128(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i16.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i16.out index c3cff320bd..cdc2a65c39 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i16.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i16.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "2176f3c0078136f3c1871f918c1b4caa271a0fcea91ec71cd5b13d0d5047ead1", type_checked_symbol_table = "1f55d2b49bf09bb9c2e703d7ea8f6c10367a7d3f75cd080ae432e1b689a93733", unrolled_symbol_table = "1f55d2b49bf09bb9c2e703d7ea8f6c10367a7d3f75cd080ae432e1b689a93733", initial_ast = "754070a6b34a912393a087cb1ecee4dc66bc7de401cdb54c760ecb28142f9695", unrolled_ast = "754070a6b34a912393a087cb1ecee4dc66bc7de401cdb54c760ecb28142f9695", ssa_ast = "4f04e60538a724a646c28ecd3a3a86991eddbb46e2cbb18b61b1458d631d8d55", flattened_ast = "b2e8226820027ff0af6d9d019db2a33b1d2021233b94794217f1a10d81694b82", destructured_ast = "0810e5a545a3f2e462d1d9156b802b8662cdc7af8da45eda19530cd50aadd003", inlined_ast = "0810e5a545a3f2e462d1d9156b802b8662cdc7af8da45eda19530cd50aadd003", dce_ast = "8c40c47afdd450175dd1e4e97a1a3cdb2bbff66665be52917b3c01cd9cbc1f7a", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i16; - output r8 as i16.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:47 + | + 27 | let a: i16 = Pedersen128::hash_to_i16(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:47 + | + 29 | let c: i16 = Pedersen128::hash_to_i16(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:47 + | + 30 | let d: i16 = Pedersen128::hash_to_i16(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:47 + | + 39 | let o: i16 = Pedersen128::hash_to_i16(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:47 + | + 41 | let q: i16 = Pedersen128::hash_to_i16(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i32.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i32.out index d7e239e9fd..5df11c0264 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i32.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i32.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "1e99433ba7238b2c6fe98b657050b05bdf7379aae0381d7e10022f6740cc5a27", type_checked_symbol_table = "5e70e9482745ef1d94670ad1278ce7d35454e3ea3d9f05c5621a6054ae824a76", unrolled_symbol_table = "5e70e9482745ef1d94670ad1278ce7d35454e3ea3d9f05c5621a6054ae824a76", initial_ast = "8e4c2ea6635cdbe3685626bbc3e94424c6ccb2cc0510867ca5bb3961f480a946", unrolled_ast = "8e4c2ea6635cdbe3685626bbc3e94424c6ccb2cc0510867ca5bb3961f480a946", ssa_ast = "004be176bab45fcf01d53f3c6d8de7156faaca14ea776c89202515caa5f8a319", flattened_ast = "dbbf294838b3ddbd5ce0c2065a1157ba3686a952e6106d68c0eaef7b957e42e5", destructured_ast = "73fddfe650474c5d4a1cd904aa4a423d7333966a428e053132767469b27cbfc1", inlined_ast = "73fddfe650474c5d4a1cd904aa4a423d7333966a428e053132767469b27cbfc1", dce_ast = "6137c54517c2e1dde6404cae9aaef48f89f9c3be11145a93fd80e2d5ec17dc25", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i32; - output r8 as i32.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:47 + | + 27 | let a: i32 = Pedersen128::hash_to_i32(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:47 + | + 29 | let c: i32 = Pedersen128::hash_to_i32(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:47 + | + 30 | let d: i32 = Pedersen128::hash_to_i32(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:47 + | + 39 | let o: i32 = Pedersen128::hash_to_i32(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:47 + | + 41 | let q: i32 = Pedersen128::hash_to_i32(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i64.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i64.out index 8db0fb0cbe..a8979e08a4 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i64.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i64.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "947f17aa9f8beb3163cd3c5946744ff5d5d4a4ad87dcf6744c3861d6b51c01c5", type_checked_symbol_table = "46c7d6eace8494858f03955180f6eec58f83de855c82eb01f71eaa2b71a722f2", unrolled_symbol_table = "46c7d6eace8494858f03955180f6eec58f83de855c82eb01f71eaa2b71a722f2", initial_ast = "3735bb203e9ca273c404572cde8f65f5dafdf3127d0f45f91b636fda3a16ee5a", unrolled_ast = "3735bb203e9ca273c404572cde8f65f5dafdf3127d0f45f91b636fda3a16ee5a", ssa_ast = "cf410d2783f4520c99a30748f3e637dba21992480eeb4b27567a038cf6c9e1ee", flattened_ast = "2af214bd1ba25129d91f2e80d0b546dfdfe4a44a3c453b93c845eee262119c53", destructured_ast = "c9634a7746cb2c81283483d04590233dbc4648fdc92d493536553ca029fc4876", inlined_ast = "c9634a7746cb2c81283483d04590233dbc4648fdc92d493536553ca029fc4876", dce_ast = "b62a5e5cfb3987276baa7bd3069ca9af862ef5f1397c72c999065cdb74e845ef", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i64; - output r8 as i64.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:47 + | + 27 | let a: i64 = Pedersen128::hash_to_i64(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:47 + | + 29 | let c: i64 = Pedersen128::hash_to_i64(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:47 + | + 30 | let d: i64 = Pedersen128::hash_to_i64(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:47 + | + 39 | let o: i64 = Pedersen128::hash_to_i64(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:47 + | + 41 | let q: i64 = Pedersen128::hash_to_i64(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i8.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i8.out index 2f5b1028ec..4d9574e9c1 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i8.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i8.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "f928b7b8c5cbf510522bcfc86ac93ec3f1701c50d6ad1d07bd149c05948a12c4", type_checked_symbol_table = "71a4f91d8767807eae3af29dab050f20acbc235002f5038d937e1e8b64526ce8", unrolled_symbol_table = "71a4f91d8767807eae3af29dab050f20acbc235002f5038d937e1e8b64526ce8", initial_ast = "18e80b0e0a72563f8016c36827af1d337871834eb676879218adcc6f3e7ee630", unrolled_ast = "18e80b0e0a72563f8016c36827af1d337871834eb676879218adcc6f3e7ee630", ssa_ast = "d19f8da5aad1f750dc672be0d90a3f5e32d2a0619f26cd993609235b12827917", flattened_ast = "1818debae697741abc83767cf15e4263f96c7622b9a639e2a71c4e0b953ccdc5", destructured_ast = "8c175160e9fd3d147862eb026f3391a619989ab26280427813fdf5a464d8e5df", inlined_ast = "8c175160e9fd3d147862eb026f3391a619989ab26280427813fdf5a464d8e5df", dce_ast = "f382b5b36c5f2883a2a145c848396aa2cba58443e79800bdb93a8e58fd0eea14", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i8; - output r8 as i8.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:45 + | + 27 | let a: i8 = Pedersen128::hash_to_i8(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:45 + | + 29 | let c: i8 = Pedersen128::hash_to_i8(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:45 + | + 30 | let d: i8 = Pedersen128::hash_to_i8(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:45 + | + 39 | let o: i8 = Pedersen128::hash_to_i8(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:45 + | + 41 | let q: i8 = Pedersen128::hash_to_i8(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u128.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u128.out index efef5a3f87..ccebb8b263 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u128.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u128.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "6b312ad86475fdfca881ccc9ccc1062f284e76aa3332675ca143caa7b5d3068b", type_checked_symbol_table = "a2f7f26b368984c3f35b5f4978a773798037cb04cee76da625fdd57037636ce3", unrolled_symbol_table = "a2f7f26b368984c3f35b5f4978a773798037cb04cee76da625fdd57037636ce3", initial_ast = "05388116d75578f3d016e968128eb49ed0fd5d1bac8263a43c0a22586db41be7", unrolled_ast = "05388116d75578f3d016e968128eb49ed0fd5d1bac8263a43c0a22586db41be7", ssa_ast = "cc93c6f8e67a6a8bea57918b876ef9259bfa9510292995ef838cf72357fcb286", flattened_ast = "fe94538f9b1c57cdf57cbc5016304637a36841988c14a5584d2f10d1791ea35d", destructured_ast = "4c0fc38d1c7eae212ccabb17424649c79e1af4a244c89b88d60dd4e705912d53", inlined_ast = "4c0fc38d1c7eae212ccabb17424649c79e1af4a244c89b88d60dd4e705912d53", dce_ast = "e5124a9eb9949bb53b783002e88d78e6ca30f385c922f32f8c12130e010b1d7b", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u128; - output r8 as u128.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:49 + | + 27 | let a: u128 = Pedersen128::hash_to_u128(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:49 + | + 29 | let c: u128 = Pedersen128::hash_to_u128(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:49 + | + 30 | let d: u128 = Pedersen128::hash_to_u128(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:49 + | + 39 | let o: u128 = Pedersen128::hash_to_u128(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:49 + | + 41 | let q: u128 = Pedersen128::hash_to_u128(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u16.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u16.out index c66792930b..2e235cf911 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u16.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u16.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "ec7e805453bb4081fba0d721a81e3f15e222fbce2d6e8587c97e24788c164bba", type_checked_symbol_table = "2f1b236449628de012306f999903e6796ada92267f38a4b32b706bfee45521eb", unrolled_symbol_table = "2f1b236449628de012306f999903e6796ada92267f38a4b32b706bfee45521eb", initial_ast = "d76d988d140f3de87ba94168a894b11126294497f96f9ff3eef463eaa902db6c", unrolled_ast = "d76d988d140f3de87ba94168a894b11126294497f96f9ff3eef463eaa902db6c", ssa_ast = "52655895eb79ec997970050f2f57c419973e1010697159020ef42a0ad90f4a62", flattened_ast = "a12499dd93bbe9b2570d2216ef540c2a677c807a22c0e13e7e3b3a3a61215dd1", destructured_ast = "1c041e3e9f86f1abdcad00d081627aaf913d2d4f6581a71d1728aa7003380ad8", inlined_ast = "1c041e3e9f86f1abdcad00d081627aaf913d2d4f6581a71d1728aa7003380ad8", dce_ast = "108d8896374ab5bcdcd6b41f221fdf9f32a4cf483680364d09c9db2cded511c2", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u16; - output r8 as u16.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:47 + | + 27 | let a: u16 = Pedersen128::hash_to_u16(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:47 + | + 29 | let c: u16 = Pedersen128::hash_to_u16(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:47 + | + 30 | let d: u16 = Pedersen128::hash_to_u16(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:47 + | + 39 | let o: u16 = Pedersen128::hash_to_u16(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:47 + | + 41 | let q: u16 = Pedersen128::hash_to_u16(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u32.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u32.out index fb4341c8f4..a225855410 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u32.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u32.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "8e28c7287c2f771e8c1edd2400fd6233cce138d7fb6d42d30d1a9e4b1695331e", type_checked_symbol_table = "7f798834b6576ad6838d62df3ef512cd13bbc1f06c48450ceab20f13c771c21c", unrolled_symbol_table = "7f798834b6576ad6838d62df3ef512cd13bbc1f06c48450ceab20f13c771c21c", initial_ast = "9386d404e9b1afebd4933a1843089ff07d33e2c23dfc9a267e1746d310d1cb39", unrolled_ast = "9386d404e9b1afebd4933a1843089ff07d33e2c23dfc9a267e1746d310d1cb39", ssa_ast = "725877a8ba4243bb9a59be0d09b46072503370c1a0e17268ac8a879147b1c056", flattened_ast = "e6c671e9800d7a1ec145015ef28a1c7074f5e463b52c28cbc1ffdbf57153dde8", destructured_ast = "61b56260ca52c5492058f66cc99d314db0dbd99e9fe92cf075684d5ab226c16a", inlined_ast = "61b56260ca52c5492058f66cc99d314db0dbd99e9fe92cf075684d5ab226c16a", dce_ast = "34aeefa58f2e6c5072f419b81b7939f6e2c5b988e596ab9b30b265628da691d2", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u32; - output r8 as u32.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:47 + | + 27 | let a: u32 = Pedersen128::hash_to_u32(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:47 + | + 29 | let c: u32 = Pedersen128::hash_to_u32(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:47 + | + 30 | let d: u32 = Pedersen128::hash_to_u32(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:47 + | + 39 | let o: u32 = Pedersen128::hash_to_u32(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:47 + | + 41 | let q: u32 = Pedersen128::hash_to_u32(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u64.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u64.out index 41aedab10c..7a31f54f65 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u64.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u64.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "a8054d139c44a5920bdea06bd84441aba853f0fa1f2a4d47745d5ad8a4c4882b", type_checked_symbol_table = "4c038d1cef171c789dbdcfe2b71f902e1f302662e235950dd361bf0d94fc39df", unrolled_symbol_table = "4c038d1cef171c789dbdcfe2b71f902e1f302662e235950dd361bf0d94fc39df", initial_ast = "5466fa327019dda719f9a90f7d70818ba08128201bde2507392c89db2e63cf77", unrolled_ast = "5466fa327019dda719f9a90f7d70818ba08128201bde2507392c89db2e63cf77", ssa_ast = "e530058e98d1af2de1ed5b422bbf57e8644307043cae4b46de19d6a07e2b2ef2", flattened_ast = "719126cfaad9b0d8b3343d4eef8ae819c562e3bbc24e478f7ed4f4456c69a27f", destructured_ast = "c597df5325a6ad32b958747e905c5fcaa59d394ef8b55581d98bffeb9f086497", inlined_ast = "c597df5325a6ad32b958747e905c5fcaa59d394ef8b55581d98bffeb9f086497", dce_ast = "dba998d8803882a5fb123211cdd7dec50f6d21781ac98727aef9f43f8f4caf3c", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u64; - output r8 as u64.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:47 + | + 27 | let a: u64 = Pedersen128::hash_to_u64(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:47 + | + 29 | let c: u64 = Pedersen128::hash_to_u64(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:47 + | + 30 | let d: u64 = Pedersen128::hash_to_u64(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:47 + | + 39 | let o: u64 = Pedersen128::hash_to_u64(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:47 + | + 41 | let q: u64 = Pedersen128::hash_to_u64(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u8.out b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u8.out index 54df55e646..e7ef0bfde4 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u8.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u8.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "20f182be4d266ff1bdf1f1fd5fdda13dfcd75a35cee0541eb15535abbf46f21f", type_checked_symbol_table = "b4c1f5ff8edadf3cd8fa58bfc3684c17700aff76b9b856b518bbb6c9a25d0bec", unrolled_symbol_table = "b4c1f5ff8edadf3cd8fa58bfc3684c17700aff76b9b856b518bbb6c9a25d0bec", initial_ast = "4be80b510dc6b6be63e6bc8e241b85cf7f0334a95fb6bd6931a08a8c3bb3f74d", unrolled_ast = "4be80b510dc6b6be63e6bc8e241b85cf7f0334a95fb6bd6931a08a8c3bb3f74d", ssa_ast = "5a581e4181f9cacf6d84a9afa7e68cb215d2eb5e12e728e4d2bc7de2e22a05dc", flattened_ast = "e79df3a96d605c9e647f3709b4c97266d4e93b5d8a84fa8d5305b83752e5dee5", destructured_ast = "a6a70f67ab43470b4768192c72cfefd60ac4d03db41632d4c7fd101de8b9b966", inlined_ast = "a6a70f67ab43470b4768192c72cfefd60ac4d03db41632d4c7fd101de8b9b966", dce_ast = "b1edd2bfdabbc088ae1eaccc5861566067d23311b277304136475a6c424c33f6", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u8; - output r8 as u8.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:27:45 + | + 27 | let a: u8 = Pedersen128::hash_to_u8(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:29:45 + | + 29 | let c: u8 = Pedersen128::hash_to_u8(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:30:45 + | + 30 | let d: u8 = Pedersen128::hash_to_u8(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:39:45 + | + 39 | let o: u8 = Pedersen128::hash_to_u8(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:41:45 + | + 41 | let q: u8 = Pedersen128::hash_to_u8(Foo { a: 1u32, b: 1u32, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i128.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i128.out index 190f498631..4e54a0e26d 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i128.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i128.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "0c5b23dfab60e1ea588e518e970d654f16b816943855029ffa265dafc3125bec", type_checked_symbol_table = "cd7464387f4fd78f7686103cbe80b1f8f8a78001e2e2bc4f2c814705a0b52254", unrolled_symbol_table = "cd7464387f4fd78f7686103cbe80b1f8f8a78001e2e2bc4f2c814705a0b52254", initial_ast = "68b9f7f7c7504a5a51fb683e227ed5769df2439679ea4324108dc4b18d7c6cd2", unrolled_ast = "68b9f7f7c7504a5a51fb683e227ed5769df2439679ea4324108dc4b18d7c6cd2", ssa_ast = "58b46f2474a10a9d8bdbc5cd7e815cb38186eaa35b4e73274e20ec2dc4db47e7", flattened_ast = "d5521383435bd6481ff51653a229976b1e40f2d52d2c11823a9966f01b62d97c", destructured_ast = "5528f2a23916979926e4d1e14599a37570535a8daf6f568d662f9bc056e9a387", inlined_ast = "5528f2a23916979926e4d1e14599a37570535a8daf6f568d662f9bc056e9a387", dce_ast = "6267df234f78df6ee75de1ed19441b3f05521e77fe62986381416aa9b05bcb90", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i128; - output r8 as i128.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:29:48 + | + 29 | let a: i128 = Pedersen64::hash_to_i128(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:31:48 + | + 31 | let c: i128 = Pedersen64::hash_to_i128(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:32:48 + | + 32 | let d: i128 = Pedersen64::hash_to_i128(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:39:48 + | + 39 | let o: i128 = Pedersen64::hash_to_i128(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:41:48 + | + 41 | let q: i128 = Pedersen64::hash_to_i128(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i16.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i16.out index 124fef6ca7..d8620d45ef 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i16.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i16.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "712ba2278b119b64cfda40f3e0eb988c30b803432d4857c5ffdc88eda2303a40", type_checked_symbol_table = "6881179a2e2fe76b54fe110627d985276a181d6723a11feb6a4ac4aa501d2be9", unrolled_symbol_table = "6881179a2e2fe76b54fe110627d985276a181d6723a11feb6a4ac4aa501d2be9", initial_ast = "b7a33b4b8154c034fdd645162dcb6e0970b43207e4da38eab90e325b1da20893", unrolled_ast = "b7a33b4b8154c034fdd645162dcb6e0970b43207e4da38eab90e325b1da20893", ssa_ast = "e4ba82a7e85f5e293a87cd4f6dc978e0cfe460791a42252b4fe8b5e6108c0792", flattened_ast = "618f18bb008dc9e7a1775b088abd462d62fbf099cc74be75b8f4a4718fbe2e3d", destructured_ast = "676f2f48de7da29b8ddfc66e8ab829a0a8973f192b8b26734f2038ce0d1d76f1", inlined_ast = "676f2f48de7da29b8ddfc66e8ab829a0a8973f192b8b26734f2038ce0d1d76f1", dce_ast = "4252e8af29756f33f2b931a7734a26e045a2a7446d30a2410846da2828b3d8ba", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i16; - output r8 as i16.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:29:46 + | + 29 | let a: i16 = Pedersen64::hash_to_i16(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:31:46 + | + 31 | let c: i16 = Pedersen64::hash_to_i16(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:32:46 + | + 32 | let d: i16 = Pedersen64::hash_to_i16(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:39:46 + | + 39 | let o: i16 = Pedersen64::hash_to_i16(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:41:46 + | + 41 | let q: i16 = Pedersen64::hash_to_i16(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i32.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i32.out index fc458cd7a2..017f52105b 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i32.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i32.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "160fba5cf2ab145e968fd94b3b699e4da872d7bc093de37d3bdf1d66e8c187ef", type_checked_symbol_table = "fca54dd10fdb2a5e761c768875018817c27be11f5bff68255d785f5cbd23ace0", unrolled_symbol_table = "fca54dd10fdb2a5e761c768875018817c27be11f5bff68255d785f5cbd23ace0", initial_ast = "c7ad27e068f9e31d5f4a579b6aae9a4d7d5098d31ec335c2a7df6cf2a88b6d5c", unrolled_ast = "c7ad27e068f9e31d5f4a579b6aae9a4d7d5098d31ec335c2a7df6cf2a88b6d5c", ssa_ast = "a88f3e17618f04390f496477a9f667cedcf7f1923e43c2e71c17c6640d0fc48f", flattened_ast = "74d7b2d2a23070867422c1c542ef45c18682d94eaba6d93382c666b4881faada", destructured_ast = "7b778c1b7c677f31a3bb48eabebe3312dc6a3efbb99a90aa8006a720054c5b15", inlined_ast = "7b778c1b7c677f31a3bb48eabebe3312dc6a3efbb99a90aa8006a720054c5b15", dce_ast = "1fd3566375218e2f0752e38f20dc92185e8b0d95791028b08258d1c1c68d9f32", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i32; - output r8 as i32.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:29:46 + | + 29 | let a: i32 = Pedersen64::hash_to_i32(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:31:46 + | + 31 | let c: i32 = Pedersen64::hash_to_i32(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:32:46 + | + 32 | let d: i32 = Pedersen64::hash_to_i32(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:39:46 + | + 39 | let o: i32 = Pedersen64::hash_to_i32(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:41:46 + | + 41 | let q: i32 = Pedersen64::hash_to_i32(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i64.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i64.out index d65d9b52d7..9b9c62ed05 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i64.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i64.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "96e81fd4c194ddc247c52899ce8785ec57e233d1beb5f9949f6e79c1cab5ae76", type_checked_symbol_table = "d9a929c37775603ba7039f3a4d536f75a9fd4add3db733f7dfbda624a6de95c0", unrolled_symbol_table = "d9a929c37775603ba7039f3a4d536f75a9fd4add3db733f7dfbda624a6de95c0", initial_ast = "14a2dc75fbbd456eb8aed9185b0b166b7e5c6db5bd05ff91edeb9c1d5dcae9dc", unrolled_ast = "14a2dc75fbbd456eb8aed9185b0b166b7e5c6db5bd05ff91edeb9c1d5dcae9dc", ssa_ast = "9d16694a286c20a02555f3bc39ba63bd615180b00fd172abb8077e7d73cd4610", flattened_ast = "280eca5d5f54e0e3adb7fd51e9604108ae4575ed083c21d9409bbc7a3f005846", destructured_ast = "321f45f8943a77ecfa454af6bc3bbd0882dc68b239e50deb3894b5b8278244cc", inlined_ast = "321f45f8943a77ecfa454af6bc3bbd0882dc68b239e50deb3894b5b8278244cc", dce_ast = "8908de64f7b09842b4177903a2623a2df445c481b20786e9a6b1989245e1a841", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i64; - output r8 as i64.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:29:46 + | + 29 | let a: i64 = Pedersen64::hash_to_i64(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:31:46 + | + 31 | let c: i64 = Pedersen64::hash_to_i64(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:32:46 + | + 32 | let d: i64 = Pedersen64::hash_to_i64(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:39:46 + | + 39 | let o: i64 = Pedersen64::hash_to_i64(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:41:46 + | + 41 | let q: i64 = Pedersen64::hash_to_i64(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i8.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i8.out index 0e0f9e0cd5..968eee83a5 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i8.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i8.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "ecb2c47dc7c6c121aa3383391698c7ad177f04fb1863e0fdc12cc6272bcfa972", type_checked_symbol_table = "0d87e7eab46179728a33c0197bafbc8830a1a09a954727ea0ec3e81427d11b0c", unrolled_symbol_table = "0d87e7eab46179728a33c0197bafbc8830a1a09a954727ea0ec3e81427d11b0c", initial_ast = "a0a6882a0c110b02294679038c0728142b2413ca33f110937d141f39a6b3e64e", unrolled_ast = "a0a6882a0c110b02294679038c0728142b2413ca33f110937d141f39a6b3e64e", ssa_ast = "e5e108ab23b2309e77f5e34b577e704f5f6de9900931c42582fbfb9b50960f5b", flattened_ast = "9295d88ec186d91cba26b0e4d19f1a38d644261d02b624c6ad2e3a7f3e4f3784", destructured_ast = "c8ff85f5aa4c8d600aff2669e39aa9a6097be4444561a804e134745075228fb2", inlined_ast = "c8ff85f5aa4c8d600aff2669e39aa9a6097be4444561a804e134745075228fb2", dce_ast = "6847b17428596f24a3b5c6b27bf1037bb126647df1a0a1fd1d7d31e54fb6bfd1", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as i8; - output r8 as i8.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:27:44 + | + 27 | let a: i8 = Pedersen64::hash_to_i8(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:29:44 + | + 29 | let c: i8 = Pedersen64::hash_to_i8(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:30:44 + | + 30 | let d: i8 = Pedersen64::hash_to_i8(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:37:44 + | + 37 | let o: i8 = Pedersen64::hash_to_i8(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:39:44 + | + 39 | let q: i8 = Pedersen64::hash_to_i8(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u128.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u128.out index f049f816f6..e8f54c3231 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u128.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u128.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "ad0c0ba49666fa9b8741106d20a60e91acd6b76cbd911976d44d990db0cb074c", type_checked_symbol_table = "0d6e6ebdc71177f59174521dc874bb2baea5abd1de4eb2cc5f5f51c08877b594", unrolled_symbol_table = "0d6e6ebdc71177f59174521dc874bb2baea5abd1de4eb2cc5f5f51c08877b594", initial_ast = "ffee7d6c150ab1b54dad107f403680324f0aee75bd2a6e0812fce86aa46f2ee2", unrolled_ast = "ffee7d6c150ab1b54dad107f403680324f0aee75bd2a6e0812fce86aa46f2ee2", ssa_ast = "1406465f29612891e3d2ee446437d8809e412aa1b643ce3ce12359e44f82d610", flattened_ast = "032582d117a7e49add220191298ee8d6c4027e245d0c1992cbcf29972c2f4374", destructured_ast = "792843993ceb51b78affe1fc51876fb06743c164cff7e0a553edf4558252caca", inlined_ast = "792843993ceb51b78affe1fc51876fb06743c164cff7e0a553edf4558252caca", dce_ast = "94acf91a3041826e5614166c0ee4c8bede2eb37bd5dbffdb275d4b47e35aaaae", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u128; - output r8 as u128.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:29:48 + | + 29 | let a: u128 = Pedersen64::hash_to_u128(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:31:48 + | + 31 | let c: u128 = Pedersen64::hash_to_u128(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:32:48 + | + 32 | let d: u128 = Pedersen64::hash_to_u128(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:39:48 + | + 39 | let o: u128 = Pedersen64::hash_to_u128(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:41:48 + | + 41 | let q: u128 = Pedersen64::hash_to_u128(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u16.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u16.out index 2e16805fc3..ea7640317e 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u16.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u16.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "9333d02fedbf611192b8ac7603d6cd75a5547610205440f01df034c7f1429266", type_checked_symbol_table = "bb92631c8360eff0d8a11ceeebe545d184e0f24e57f4e03ef4a33efa6183e3f8", unrolled_symbol_table = "bb92631c8360eff0d8a11ceeebe545d184e0f24e57f4e03ef4a33efa6183e3f8", initial_ast = "23f1cfeb5ded0a386597ac1ed019ff7906d3bf31c2124f5aa0c6b6289a1fedd7", unrolled_ast = "23f1cfeb5ded0a386597ac1ed019ff7906d3bf31c2124f5aa0c6b6289a1fedd7", ssa_ast = "67e881b8a0c853ab46b3bdbda543e99a9047b59ac03cc59656109e7e08bf3fc4", flattened_ast = "27cea8d4bbd11b33c828a7241c31dd8990424b825e3fb73bb99f297f1cc04f66", destructured_ast = "8030b6ae11db9610277d3630c3d5a54889028a6b99385ff9e3c39f665d894731", inlined_ast = "8030b6ae11db9610277d3630c3d5a54889028a6b99385ff9e3c39f665d894731", dce_ast = "967aac06caf5b7e8aa98f98ad764c6a029105235205558c26db189d81dace023", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u16; - output r8 as u16.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:29:46 + | + 29 | let a: u16 = Pedersen64::hash_to_u16(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:31:46 + | + 31 | let c: u16 = Pedersen64::hash_to_u16(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:32:46 + | + 32 | let d: u16 = Pedersen64::hash_to_u16(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:39:46 + | + 39 | let o: u16 = Pedersen64::hash_to_u16(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:41:46 + | + 41 | let q: u16 = Pedersen64::hash_to_u16(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u32.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u32.out index 50d95fd273..49d686c27e 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u32.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u32.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "bcbb74fefed2f406308cad56c692eb6abeb05b2c8714503cc548e3d85857f712", type_checked_symbol_table = "304037e017528b1b031d58b47acd0cf49845bf519d3f92a6d30db7853bc03307", unrolled_symbol_table = "304037e017528b1b031d58b47acd0cf49845bf519d3f92a6d30db7853bc03307", initial_ast = "29fb669950c75c3e68357cd07ade8e2f4da77b74db137b78e8a9164290f33f40", unrolled_ast = "29fb669950c75c3e68357cd07ade8e2f4da77b74db137b78e8a9164290f33f40", ssa_ast = "7ae7464f03756218449e0fef6f0865578b52b3eec881d439cdb4ed787e2aee94", flattened_ast = "e54a4424efebf9e6aa2665507232d7c148e49e5b786c926c26ea573743b3b9ee", destructured_ast = "23a092f35286253af0b458ec6fc5fc4a1417b4c0a9064cc477dc5098ab737722", inlined_ast = "23a092f35286253af0b458ec6fc5fc4a1417b4c0a9064cc477dc5098ab737722", dce_ast = "913294ec9edf1c3776dc99b283f8be4b14e8d47e60a45b3357e0e8df1c7943bc", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u32; - output r8 as u32.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:29:46 + | + 29 | let a: u32 = Pedersen64::hash_to_u32(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:31:46 + | + 31 | let c: u32 = Pedersen64::hash_to_u32(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:32:46 + | + 32 | let d: u32 = Pedersen64::hash_to_u32(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:39:46 + | + 39 | let o: u32 = Pedersen64::hash_to_u32(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:41:46 + | + 41 | let q: u32 = Pedersen64::hash_to_u32(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u64.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u64.out index 2806322f9c..c513ccd841 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u64.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u64.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "0cfd8b0cb21561fb7554996f3edbc883fc170dace49d5f0839bb52b8d7800d19", type_checked_symbol_table = "5f0c9faa2523b7bf3a0c25bfc4431ca84519d9146dce75f01c7fda74d43f02b4", unrolled_symbol_table = "5f0c9faa2523b7bf3a0c25bfc4431ca84519d9146dce75f01c7fda74d43f02b4", initial_ast = "a16e9c1f4ea1aa8d80c0c3b4599597a8795bd8408b00b79bf5a5ba80849bf701", unrolled_ast = "a16e9c1f4ea1aa8d80c0c3b4599597a8795bd8408b00b79bf5a5ba80849bf701", ssa_ast = "8df24f8bba330d3d907673277d830b30ef7469cbe7dc29d11c62a36dd800d192", flattened_ast = "c0ca1ea2f49dfb3ad0812db589a62518d29a799548fef7de5d43792a498bfa12", destructured_ast = "42bfa93bd57da697e33233e8d60344b98a49563f3528efdf15c08e1885548973", inlined_ast = "42bfa93bd57da697e33233e8d60344b98a49563f3528efdf15c08e1885548973", dce_ast = "43f0df4f48ceaf766aeb542dc4b610c79b041dfba2b7158b537674a671bd1400", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u64; - output r8 as u64.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:29:46 + | + 29 | let a: u64 = Pedersen64::hash_to_u64(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:31:46 + | + 31 | let c: u64 = Pedersen64::hash_to_u64(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:32:46 + | + 32 | let d: u64 = Pedersen64::hash_to_u64(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:39:46 + | + 39 | let o: u64 = Pedersen64::hash_to_u64(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:41:46 + | + 41 | let q: u64 = Pedersen64::hash_to_u64(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u8.out b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u8.out index 2e175b1072..f2134701c4 100644 --- a/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u8.out +++ b/tests/expectations/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u8.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "2ef869c3e63096f9847e1eb6f4914d54e9cf70ea62b02c077b94cdbd859bb16d", type_checked_symbol_table = "6c9e2246215d533a3b51a7fbb9c81c4572ddc2a6541386fc7507a832aaaa7150", unrolled_symbol_table = "6c9e2246215d533a3b51a7fbb9c81c4572ddc2a6541386fc7507a832aaaa7150", initial_ast = "1676293a5dce7cf02649a2ecedf739a5600e095c4f5797ee3a559451e153bc72", unrolled_ast = "1676293a5dce7cf02649a2ecedf739a5600e095c4f5797ee3a559451e153bc72", ssa_ast = "80f867e3c82165605b9b12c842564a0c8cf3de4e8782f22f4c8296b7ef9ea390", flattened_ast = "d15bfbfe5556102d82fc1a34957c23f8a5cf646594c2f2c31aba5c8211b13997", destructured_ast = "06614749740fb6275ee9779f480d8e1f9e03950894011d7d15c522ac029610ab", inlined_ast = "06614749740fb6275ee9779f480d8e1f9e03950894011d7d15c522ac029610ab", dce_ast = "9ce604662c2090fe91e2188565507603189b55c80c02c839abb4231c51cc44a0", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as u8; - output r8 as u8.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:29:44 + | + 29 | let a: u8 = Pedersen64::hash_to_u8(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:31:44 + | + 31 | let c: u8 = Pedersen64::hash_to_u8(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:32:44 + | + 32 | let d: u8 = Pedersen64::hash_to_u8(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:39:44 + | + 39 | let o: u8 = Pedersen64::hash_to_u8(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:41:44 + | + 41 | let q: u8 = Pedersen64::hash_to_u8(Foo { a: 1u16, b: 1u16, }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_address.out b/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_address.out index e2b984ea69..50ea2f84d5 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_address.out +++ b/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_address.out @@ -1,23 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "501d55f20d3f1a572c2a5c1bbaeb74c0daf60d60206e00a480f3515a8b317d72", type_checked_symbol_table = "cf18ef0906051a43a21927ca8ab931709985574f7a0c257ed0a3bde10886db41", unrolled_symbol_table = "cf18ef0906051a43a21927ca8ab931709985574f7a0c257ed0a3bde10886db41", initial_ast = "d10b8955d24f0ea00219c01c7b98dca6019e7e470ceee990ed117c7add0cb463", unrolled_ast = "d10b8955d24f0ea00219c01c7b98dca6019e7e470ceee990ed117c7add0cb463", ssa_ast = "5004830327a5db55b58e950850b05b991574c644027dc6ab56484e685e25463e", flattened_ast = "9ef1fd1aa11b35cabc0a6de842e57eef43e50fd69ad24b3d3e7f7678daad7af4", destructured_ast = "b5c766a35043afd037da5869b81c212a8086d13c3c596379c60f605000c4a3a9", inlined_ast = "b5c766a35043afd037da5869b81c212a8086d13c3c596379c60f605000c4a3a9", dce_ast = "3838b540951a48634c3c008076e9ab64017ad6cc5cf022d30bbf75f590b47b12", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - commit.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta 1scalar into r8 as address; - commit.ped128 r4 1scalar into r9 as address; - is.eq r8 r9 into r10; - output r10 as boolean.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:29:57 + | + 29 | let a: address = Pedersen128::commit_to_address(addr_value, scalar_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:31:57 + | + 31 | let c: address = Pedersen128::commit_to_address(field_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:32:57 + | + 32 | let d: address = Pedersen128::commit_to_address(group_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:41:57 + | + 41 | let o: address = Pedersen128::commit_to_address(scalar_value, scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:43:57 + | + 43 | let p: address = Pedersen128::commit_to_address(Foo { a: 1u32, b: 1u32 }, scalar_value); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_field.out b/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_field.out index 0aee75c193..11f3f1a2f6 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_field.out +++ b/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_field.out @@ -1,23 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "501d55f20d3f1a572c2a5c1bbaeb74c0daf60d60206e00a480f3515a8b317d72", type_checked_symbol_table = "db0f89fb855e13d2099b675fb8bdcd27ba69a43b194a757953cdafa5e0a3c089", unrolled_symbol_table = "db0f89fb855e13d2099b675fb8bdcd27ba69a43b194a757953cdafa5e0a3c089", initial_ast = "2c74e033d97e0550d5f3e7f8919abf3b1be853d3a026689e18a27f4e4c8f7100", unrolled_ast = "2c74e033d97e0550d5f3e7f8919abf3b1be853d3a026689e18a27f4e4c8f7100", ssa_ast = "0cb8161b427eac17a3f7d07d3a255eb874b0a81b1ff9efe5c841d8cc6ebeddd8", flattened_ast = "91e4a5bc4a66cff29a030e463aa749d2fc8739ca7e1f743de288efdf8652d031", destructured_ast = "1e4f728da69529a555a7ebb82d4b6aa440c85b53d2f412fc09f7bcff0bf6a303", inlined_ast = "1e4f728da69529a555a7ebb82d4b6aa440c85b53d2f412fc09f7bcff0bf6a303", dce_ast = "258e64b46de98d4d07352e03e6c5053dc7cbc7cc5f3db4dab5894b62c003a911", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - commit.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta 1scalar into r8 as field; - commit.ped128 r4 1scalar into r9 as field; - is.eq r8 r9 into r10; - output r10 as boolean.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:29:53 + | + 29 | let a: field = Pedersen128::commit_to_field(addr_value, scalar_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:31:53 + | + 31 | let c: field = Pedersen128::commit_to_field(field_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:32:53 + | + 32 | let d: field = Pedersen128::commit_to_field(group_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:41:53 + | + 41 | let o: field = Pedersen128::commit_to_field(scalar_value, scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:43:53 + | + 43 | let p: field = Pedersen128::commit_to_field(Foo { a: 1u32, b: 1u32 }, scalar_value); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_group.out b/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_group.out index e2f8e2fda3..bd2ee9cd8a 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_group.out +++ b/tests/expectations/compiler/core/algorithms/pedersen128_commit_to_group.out @@ -1,23 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "501d55f20d3f1a572c2a5c1bbaeb74c0daf60d60206e00a480f3515a8b317d72", type_checked_symbol_table = "1aa442be13d523c657fc34987bda9b954d70ce031810252ecd4bcf113fbc7fce", unrolled_symbol_table = "1aa442be13d523c657fc34987bda9b954d70ce031810252ecd4bcf113fbc7fce", initial_ast = "fcd43cf43733b1c80e5ae0ac563bdda3b99b39e2658d7bf18543b69bc0f31587", unrolled_ast = "fcd43cf43733b1c80e5ae0ac563bdda3b99b39e2658d7bf18543b69bc0f31587", ssa_ast = "a3dae9e52567781081f49837c75b13719fbe1fc46f67cce47094b62503d99dac", flattened_ast = "ebb0770add34a77d532c129bc5fee8bc74437ea5defe6d34ff13fa5f52c35b35", destructured_ast = "cefcad555acdf4f13571984d63bf82ac0d766578951034aee7e12ba3c22a0239", inlined_ast = "cefcad555acdf4f13571984d63bf82ac0d766578951034aee7e12ba3c22a0239", dce_ast = "77e21e5096a1ec4f19060b73c42142a29dfca584ac2f89fe8e1750b4f0c55193", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - commit.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta 1scalar into r8 as group; - commit.ped128 r4 1scalar into r9 as group; - is.eq r8 r9 into r10; - output r10 as boolean.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:29:53 + | + 29 | let a: group = Pedersen128::commit_to_group(addr_value, scalar_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:31:53 + | + 31 | let c: group = Pedersen128::commit_to_group(field_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:32:53 + | + 32 | let d: group = Pedersen128::commit_to_group(group_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:41:53 + | + 41 | let o: group = Pedersen128::commit_to_group(scalar_value, scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:43:53 + | + 43 | let p: group = Pedersen128::commit_to_group(Foo { a: 1u32, b: 1u32 }, scalar_value); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_address.out b/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_address.out index cec4cbdb49..bdc233408b 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_address.out +++ b/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_address.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "9a9ce539c5db1390d701f8f9cce7591f1aadb958544c76640332f89dc4871818", type_checked_symbol_table = "9e0c93b497a4e4ea4adb478df544aacf04b210ca3be8448127a19746517fd4f0", unrolled_symbol_table = "9e0c93b497a4e4ea4adb478df544aacf04b210ca3be8448127a19746517fd4f0", initial_ast = "2887a87b28ce882ef5eb92729940e91f3eab8a2f5efb96eefe325be750373b1d", unrolled_ast = "2887a87b28ce882ef5eb92729940e91f3eab8a2f5efb96eefe325be750373b1d", ssa_ast = "fb7dca997fec396d9a20feda66d5a292d7ba39a11e9de8f5bf86843ad608720b", flattened_ast = "48c35557707bcfce348e1acef81c87bccd7f79bcd01d03c36438070bfb5bd755", destructured_ast = "86c4c74fa0be1fff02c706d16c646cb412733cc3617c3d353290d409479a20f1", inlined_ast = "86c4c74fa0be1fff02c706d16c646cb412733cc3617c3d353290d409479a20f1", dce_ast = "0afa089fff57677dc8ed2d4ae6f86797bc100b7a424fbc50964ce7c53b372e31", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as address; - output r8 as address.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:29:55 + | + 29 | let a: address = Pedersen128::hash_to_address(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:31:55 + | + 31 | let c: address = Pedersen128::hash_to_address(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:32:55 + | + 32 | let d: address = Pedersen128::hash_to_address(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:41:55 + | + 41 | let o: address = Pedersen128::hash_to_address(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:43:55 + | + 43 | let p: address = Pedersen128::hash_to_address(Foo { a: 1u32, b: 1u32 }); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_field.out b/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_field.out index bc4daaea04..37bfe58794 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_field.out +++ b/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_field.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "b35030986eebd8b0f4055bf0de55fcacad27b202140cd222e80e5a5fcf3b27d1", type_checked_symbol_table = "8e04c85b3774cd9fb55d3811d31a6994e1b3e104c6bd7d5d3ccea9118c44c4d0", unrolled_symbol_table = "8e04c85b3774cd9fb55d3811d31a6994e1b3e104c6bd7d5d3ccea9118c44c4d0", initial_ast = "0c91a79da594ce1ad93542859de7a531eec81fe516abea9d3f0713c341dd1529", unrolled_ast = "0c91a79da594ce1ad93542859de7a531eec81fe516abea9d3f0713c341dd1529", ssa_ast = "7dedeb6948a89d9f6bca8c8ddd098fbe96907ae54bb3856e8a06b41f82c0d5ba", flattened_ast = "8f0b6d487d54ee8eb8c294245dea631b9954c21970e64fe7fb30efb238ed5bd0", destructured_ast = "8944cb65be76a42e79525eebbe2dbbbe8095b6add0b3aaa228d280e0b7f3c7b5", inlined_ast = "8944cb65be76a42e79525eebbe2dbbbe8095b6add0b3aaa228d280e0b7f3c7b5", dce_ast = "3f0e9fd891a8f845d5c151de786813853aea8977d11005cbc9a8212fb8ec6b16", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as field; - output r8 as field.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:29:51 + | + 29 | let a: field = Pedersen128::hash_to_field(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:31:51 + | + 31 | let c: field = Pedersen128::hash_to_field(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:32:51 + | + 32 | let d: field = Pedersen128::hash_to_field(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:41:51 + | + 41 | let o: field = Pedersen128::hash_to_field(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:43:51 + | + 43 | let p: field = Pedersen128::hash_to_field(Foo { a: 1u32, b: 1u32 }); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_group.out b/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_group.out index 1fa5d40af3..c7607fd7dd 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_group.out +++ b/tests/expectations/compiler/core/algorithms/pedersen128_hash_to_group.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "cf8f80111fec71cb16c98d580e6efeaed5f641ea2361ff82b16c2640fb48b69e", type_checked_symbol_table = "163f2c1b2f4e2fe77e6ef2c9b03c550c107e4b73a64cc83f98c9ba08b435f154", unrolled_symbol_table = "163f2c1b2f4e2fe77e6ef2c9b03c550c107e4b73a64cc83f98c9ba08b435f154", initial_ast = "1064081f294b843439e010fb00822250d8f6f6f1410540cd2c72cf5a3f2c156d", unrolled_ast = "1064081f294b843439e010fb00822250d8f6f6f1410540cd2c72cf5a3f2c156d", ssa_ast = "33a5335359ab9b7c4fcba04f8bfd298a8d79fba379ad48ec1b872bfc09246a3a", flattened_ast = "48e7c30f14e8a9b5101c86462e567f4f1e1db508cb9dd6ba6396cacd8e7f8749", destructured_ast = "3075ceb16742cc16565713e2f31c27b1cc0b8331e409d6324dfdc2e8aaf4e8fc", inlined_ast = "3075ceb16742cc16565713e2f31c27b1cc0b8331e409d6324dfdc2e8aaf4e8fc", dce_ast = "56a45ef1487fbf9edd3bc29a3bdb35c3bb819cfbea63ad06d94f279b38852839", bytecode = """ -program test.aleo; - -struct Foo: - a as u32; - b as u32; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped128 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as group; - output r8 as group.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `address` was found + --> compiler-test:29:51 + | + 29 | let a: group = Pedersen128::hash_to_group(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `field` was found + --> compiler-test:31:51 + | + 31 | let c: group = Pedersen128::hash_to_group(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `group` was found + --> compiler-test:32:51 + | + 32 | let d: group = Pedersen128::hash_to_group(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `scalar` was found + --> compiler-test:41:51 + | + 41 | let o: group = Pedersen128::hash_to_group(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 128 bits or a bool` but type `Foo` was found + --> compiler-test:43:51 + | + 43 | let p: group = Pedersen128::hash_to_group(Foo { a: 1u32, b: 1u32 }); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_address.out b/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_address.out index 1406c9150c..79a7629626 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_address.out +++ b/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_address.out @@ -1,23 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "98f0b93406bc0ab5d755fb4d4da966be418df82f4a376f328dad3769a95db3eb", type_checked_symbol_table = "11054f75a159ca0743eacced1983df41112cec5fdf165580c515cb3b1bb7be49", unrolled_symbol_table = "11054f75a159ca0743eacced1983df41112cec5fdf165580c515cb3b1bb7be49", initial_ast = "0eafa3b3da0309e63d52b02abb716e3f7eb9783b84e483d423f25e80cc35c5ef", unrolled_ast = "0eafa3b3da0309e63d52b02abb716e3f7eb9783b84e483d423f25e80cc35c5ef", ssa_ast = "f114c8496fb38b819ca571cdff6b0445107372c294060da5cc4bedb0d23ca6b0", flattened_ast = "72c434f620c87913414ae76719411c02a0f05adfd01465c8718cc3606c1478cf", destructured_ast = "a98b315b4994e3b9c1d2ec0f56c0cb7e838f16ebc923516e72d6d5bdb05ffb2c", inlined_ast = "a98b315b4994e3b9c1d2ec0f56c0cb7e838f16ebc923516e72d6d5bdb05ffb2c", dce_ast = "d09def911096b772d6b27b93a98f359eb337ae58879a659d2d34437f0c0a13b2", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - commit.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta 1scalar into r8 as address; - commit.ped64 r4 1scalar into r9 as address; - is.eq r8 r9 into r10; - output r10 as boolean.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:27:56 + | + 27 | let a: address = Pedersen64::commit_to_address(addr_value, scalar_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:29:56 + | + 29 | let c: address = Pedersen64::commit_to_address(field_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:30:56 + | + 30 | let d: address = Pedersen64::commit_to_address(group_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:37:56 + | + 37 | let m: address = Pedersen64::commit_to_address(scalar_value, scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:39:56 + | + 39 | let n: address = Pedersen64::commit_to_address(Foo { a: 1u16, b: 1u16 }, scalar_value); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_field.out b/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_field.out index 62a8efe98a..8f16853a54 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_field.out +++ b/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_field.out @@ -1,23 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "98f0b93406bc0ab5d755fb4d4da966be418df82f4a376f328dad3769a95db3eb", type_checked_symbol_table = "19fdc82ac5ff496005c573c64ba8a023dd017a7d4447d3779cede32f34559b39", unrolled_symbol_table = "19fdc82ac5ff496005c573c64ba8a023dd017a7d4447d3779cede32f34559b39", initial_ast = "90b835d4281bd7caf76cd9cb3e0e351e873618c31dbdbe7e0e68a54b964a437e", unrolled_ast = "90b835d4281bd7caf76cd9cb3e0e351e873618c31dbdbe7e0e68a54b964a437e", ssa_ast = "2698b5c4b8aefce178266aa6ff04a96ef1a8fde0cd76e0a1c7797c519a61271f", flattened_ast = "420e05f69ec8f5f36bd0610e53205edb50f724824c9c99ab74ee89cef03d8bc5", destructured_ast = "8cb8388a9d032f0e41d9fc497dd53a806b4cbf3dd8b2a2f76fad9bebad617848", inlined_ast = "8cb8388a9d032f0e41d9fc497dd53a806b4cbf3dd8b2a2f76fad9bebad617848", dce_ast = "7aeb4ca69132188ebcc3ddefbd593988585d4011c26dcfd61d4e2cd9368bfcbd", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - commit.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta 1scalar into r8 as field; - commit.ped64 r4 1scalar into r9 as field; - is.eq r8 r9 into r10; - output r10 as boolean.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:27:52 + | + 27 | let a: field = Pedersen64::commit_to_field(addr_value, scalar_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:29:52 + | + 29 | let c: field = Pedersen64::commit_to_field(field_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:30:52 + | + 30 | let d: field = Pedersen64::commit_to_field(group_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:37:52 + | + 37 | let m: field = Pedersen64::commit_to_field(scalar_value, scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:39:52 + | + 39 | let n: field = Pedersen64::commit_to_field(Foo { a: 1u16, b: 1u16 }, scalar_value); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_group.out b/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_group.out index 7a61bfae3f..52bea9b9d0 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_group.out +++ b/tests/expectations/compiler/core/algorithms/pedersen64_commit_to_group.out @@ -1,23 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "98f0b93406bc0ab5d755fb4d4da966be418df82f4a376f328dad3769a95db3eb", type_checked_symbol_table = "36395772cc753c8445b1891d3eca79be770019b5f9be35dec15c4daa437dd0fb", unrolled_symbol_table = "36395772cc753c8445b1891d3eca79be770019b5f9be35dec15c4daa437dd0fb", initial_ast = "594a14284059b421b9b836a46a0063c3ad6a992364dc05add652eb226fbe2a07", unrolled_ast = "594a14284059b421b9b836a46a0063c3ad6a992364dc05add652eb226fbe2a07", ssa_ast = "ede6f692866dadf3e2b5de89cce9479e661e4f2a35cb510e5d57e17537577ac6", flattened_ast = "37187dc61d74852dad5ed54df704e576960cf81c259cd94ce14c1bcd5d4081a2", destructured_ast = "43a99b40ee568b1cfac907cc4205d60ec74ef59ddd68553402d4a652de22f5f2", inlined_ast = "43a99b40ee568b1cfac907cc4205d60ec74ef59ddd68553402d4a652de22f5f2", dce_ast = "226dff47c2f977b5a88781f5f41ad9e0fb73b805c7de2477c1773d85ea895ccb", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - commit.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta 1scalar into r8 as group; - commit.ped64 r4 1scalar into r9 as group; - is.eq r8 r9 into r10; - output r10 as boolean.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:27:52 + | + 27 | let a: group = Pedersen64::commit_to_group(addr_value, scalar_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:29:52 + | + 29 | let c: group = Pedersen64::commit_to_group(field_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:30:52 + | + 30 | let d: group = Pedersen64::commit_to_group(group_value, scalar_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:37:52 + | + 37 | let m: group = Pedersen64::commit_to_group(scalar_value, scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:39:52 + | + 39 | let n: group = Pedersen64::commit_to_group(Foo { a: 1u16, b: 1u16 }, scalar_value); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_address.out b/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_address.out index 592e54439b..8a9e836009 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_address.out +++ b/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_address.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "f5a5776350ce988c849ddfd1aeb1007326534cabeeb69d8067d0896254bea044", type_checked_symbol_table = "78c54cb0462f628ab9c405f80e6c7fb1ed97e40cb058848de5c8db24607a826b", unrolled_symbol_table = "78c54cb0462f628ab9c405f80e6c7fb1ed97e40cb058848de5c8db24607a826b", initial_ast = "99073126c73dd8a427a183ff2c8d249141f93b0be0202e08ea13a37756c2c1d3", unrolled_ast = "99073126c73dd8a427a183ff2c8d249141f93b0be0202e08ea13a37756c2c1d3", ssa_ast = "251491d86d9f06ff7f36c76bf5e29140075b89729dac0e0c1f1db23e63ac4897", flattened_ast = "786f3f8d419330faae2e10fe6452d9f86a3befbd3323fec82f03323be98fc86c", destructured_ast = "c99dc2d8428ea9698158d4bba41d497ba5a2b571c1e26ddc4527193a76145808", inlined_ast = "c99dc2d8428ea9698158d4bba41d497ba5a2b571c1e26ddc4527193a76145808", dce_ast = "1073639e1e5bc85e79bbb610de53d6763579b3db3a39c2b3ef24ad0328d80223", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as address; - output r8 as address.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:27:54 + | + 27 | let a: address = Pedersen64::hash_to_address(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:29:54 + | + 29 | let c: address = Pedersen64::hash_to_address(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:30:54 + | + 30 | let d: address = Pedersen64::hash_to_address(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:37:54 + | + 37 | let m: address = Pedersen64::hash_to_address(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:39:54 + | + 39 | let n: address = Pedersen64::hash_to_address(Foo { a: 1u16, b: 1u16 }); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_field.out b/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_field.out index 44bf81be50..77938b1bdd 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_field.out +++ b/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_field.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "56b062bf23a1f61497942aee31138e1720a2317d48413c9eb73b9bfa13a05374", type_checked_symbol_table = "66f651c0e17c985596a76f27e064ad569a16522666a7089f257bad259ace7ffd", unrolled_symbol_table = "66f651c0e17c985596a76f27e064ad569a16522666a7089f257bad259ace7ffd", initial_ast = "125a949338482710e7ca3c35841f673e8464c45ad0c9b88a730fc65c33c63755", unrolled_ast = "125a949338482710e7ca3c35841f673e8464c45ad0c9b88a730fc65c33c63755", ssa_ast = "3fb59f5d060ca06bc791fcce8eb098244780b09de14bfe7dba933dfd27c2668a", flattened_ast = "a8cc36c11a15899f6744515b69fdf643c16669c4a316f46bca325a11b3d33461", destructured_ast = "ca33a64950598312b81a6d1334224a15da96a9fd344f5d922f3daef619cfae88", inlined_ast = "ca33a64950598312b81a6d1334224a15da96a9fd344f5d922f3daef619cfae88", dce_ast = "2eb59567caeb4750790eca44fdf113b0d66a10f1a8868441d5d7d01aa16e15dd", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as field; - output r8 as field.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:27:50 + | + 27 | let a: field = Pedersen64::hash_to_field(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:29:50 + | + 29 | let c: field = Pedersen64::hash_to_field(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:30:50 + | + 30 | let d: field = Pedersen64::hash_to_field(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:37:50 + | + 37 | let m: field = Pedersen64::hash_to_field(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:39:50 + | + 39 | let n: field = Pedersen64::hash_to_field(Foo { a: 1u16, b: 1u16 }); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_group.out b/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_group.out index 1387ef9904..cc7d8e5eec 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_group.out +++ b/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_group.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "2061db24723ed76bf97af34ce45e35f364266c59c8f4ae691707ca2b0ba1a517", type_checked_symbol_table = "2b66182ba431f03b24fc5216c30db08b63717561f4c752e8bc1f0d8a75d08b08", unrolled_symbol_table = "2b66182ba431f03b24fc5216c30db08b63717561f4c752e8bc1f0d8a75d08b08", initial_ast = "d18c2d27b71c443e3b2696aaad60a0fdfbea0ce4aa4f3fe9affef7da1634d4ef", unrolled_ast = "d18c2d27b71c443e3b2696aaad60a0fdfbea0ce4aa4f3fe9affef7da1634d4ef", ssa_ast = "981789579c5f8b63c754976b41f0a746ecfa7f33328acbd9c2c6cb55551e1f8f", flattened_ast = "e418f30466f92b73c05831339977587deb301fb9b7b5605ee50ea608a55b16a2", destructured_ast = "daf3c4d141acbde48ecc278a548e507cd5f50374db66d9d81e3f5bff03d84f74", inlined_ast = "daf3c4d141acbde48ecc278a548e507cd5f50374db66d9d81e3f5bff03d84f74", dce_ast = "15479a266cf6e4ddef14c7aaae33d4dbd84b80a392c070edf963aa63be6c3778", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as group; - output r8 as group.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:27:50 + | + 27 | let a: group = Pedersen64::hash_to_group(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:29:50 + | + 29 | let c: group = Pedersen64::hash_to_group(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:30:50 + | + 30 | let d: group = Pedersen64::hash_to_group(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:37:50 + | + 37 | let m: group = Pedersen64::hash_to_group(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:39:50 + | + 39 | let n: group = Pedersen64::hash_to_group(Foo { a: 1u16, b: 1u16 }); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_scalar.out b/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_scalar.out index 678c0cade0..796bc0c10a 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_scalar.out +++ b/tests/expectations/compiler/core/algorithms/pedersen64_hash_to_scalar.out @@ -1,21 +1,29 @@ namespace = "Compile" -expectation = "Pass" -outputs = [[{ compile = [{ initial_symbol_table = "06e11747d399574731bca182b2e1d20f739bb7ab8a39371982a4d13c1e55f7c7", type_checked_symbol_table = "b2c3d8c76e3e998845f610cd7baf8140a325e038f54736a6c3b04792d84880b8", unrolled_symbol_table = "b2c3d8c76e3e998845f610cd7baf8140a325e038f54736a6c3b04792d84880b8", initial_ast = "cb8e967fdf1777efe567de13891b0da23998aaf187904fa5f8d35cf7a49348a1", unrolled_ast = "cb8e967fdf1777efe567de13891b0da23998aaf187904fa5f8d35cf7a49348a1", ssa_ast = "b66a9a70ae78f3d3e3ca299f3d7880b33c228d18a5dcd28168f676acb87f331d", flattened_ast = "b6a2ead1af7c66a6989981646bd473264216d8f1427bb906ff12062048356b40", destructured_ast = "a669f9d1930eb958881871e006285cf23c4779903fb11ed88d871f1dd7b5d904", inlined_ast = "a669f9d1930eb958881871e006285cf23c4779903fb11ed88d871f1dd7b5d904", dce_ast = "f9eafbb3278de0ec7e2315592b5546e593341f5b086f5c2a558b086490525e83", bytecode = """ -program test.aleo; - -struct Foo: - a as u16; - b as u16; - -function main: - input r0 as i8.private; - input r1 as i16.private; - input r2 as i32.private; - input r3 as i64.private; - input r4 as u8.private; - input r5 as u16.private; - input r6 as u32.private; - input r7 as u64.private; - hash.ped64 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r8 as scalar; - output r8 as scalar.private; -""", errors = "", warnings = "" }] }]] +expectation = "Fail" +outputs = [""" +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `address` was found + --> compiler-test:27:52 + | + 27 | let a: scalar = Pedersen64::hash_to_scalar(addr_value); + | ^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `field` was found + --> compiler-test:29:52 + | + 29 | let c: scalar = Pedersen64::hash_to_scalar(field_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `group` was found + --> compiler-test:30:52 + | + 30 | let d: scalar = Pedersen64::hash_to_scalar(group_value); + | ^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `scalar` was found + --> compiler-test:37:52 + | + 37 | let m: scalar = Pedersen64::hash_to_scalar(scalar_value); + | ^^^^^^^^^^^^ +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `Foo` was found + --> compiler-test:39:52 + | + 39 | let n: scalar = Pedersen64::hash_to_scalar(Foo { a: 1u16, b: 1u16 }); + | ^^^^^^^^^^^^^^^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/core/algorithms/pedersen_fail.out b/tests/expectations/compiler/core/algorithms/pedersen_fail.out index 1bdb8bb065..e098a606e1 100644 --- a/tests/expectations/compiler/core/algorithms/pedersen_fail.out +++ b/tests/expectations/compiler/core/algorithms/pedersen_fail.out @@ -1,12 +1,12 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372007]: Expected one type from `address, bool, field, group, struct, integer, scalar, struct`, but got `u128` +Error [ETYC0372003]: Expected type `an integer of less than 64 bits or a bool` but type `u128` was found --> compiler-test:5:50 | 5 | let a: group = Pedersen64::hash_to_field(1u128); // Pedersen64 hash_to_field returns a field type | ^^^^^ -Error [ETYC0372003]: Expected type `group` but type `field` was found +Error [ETYC0372117]: Expected type `group` but type `field` was found. --> compiler-test:5:24 | 5 | let a: group = Pedersen64::hash_to_field(1u128); // Pedersen64 hash_to_field returns a field type diff --git a/tests/expectations/compiler/core/cheatcodes/invalid_cheatcodes_fail.out b/tests/expectations/compiler/core/cheatcodes/invalid_cheatcodes_fail.out index 4205dced3d..47ead9d462 100644 --- a/tests/expectations/compiler/core/cheatcodes/invalid_cheatcodes_fail.out +++ b/tests/expectations/compiler/core/cheatcodes/invalid_cheatcodes_fail.out @@ -11,12 +11,12 @@ Error [ETYC0372005]: Unknown variable `account` | 14 | CheatCode::print_mapping(test_dep.aleo/account); | ^^^^^^^^^^^^^^^^^^^^^ -Error [ETYC0372003]: Expected type `u32` but type `u64` was found +Error [ETYC0372117]: Expected type `u32` but type `u64` was found. --> compiler-test:15:37 | 15 | CheatCode::set_block_height(1u64); | ^^^^ -Error [ETYC0372003]: Expected type `u32` but type `u64` was found +Error [ETYC0372117]: Expected type `u32` but type `u64` was found. --> compiler-test:16:37 | 16 | CheatCode::set_block_height(a); diff --git a/tests/expectations/compiler/definition/define_multiple_variables_fail.out b/tests/expectations/compiler/definition/define_multiple_variables_fail.out index 8d1523dbb2..78712962ef 100644 --- a/tests/expectations/compiler/definition/define_multiple_variables_fail.out +++ b/tests/expectations/compiler/definition/define_multiple_variables_fail.out @@ -11,7 +11,7 @@ Error [ETYC0372072]: Expected a tuple with 3 elements, found one with 2 elements | 6 | let (d,e): (u8,u8,u8) = (1u8,2u8,3u8); | ^^^^^ -Error [ETYC0372003]: Expected type `(u8,u8,u8)` but type `u8` was found +Error [ETYC0372117]: Expected type `(u8, u8, u8)` but type `u8` was found. --> compiler-test:7:36 | 7 | let (g,h,i): (u8,u8,u8) = (1u8); diff --git a/tests/expectations/compiler/expression/cast_fail.out b/tests/expectations/compiler/expression/cast_fail.out index 55c1c89e4d..e8648257e4 100644 --- a/tests/expectations/compiler/expression/cast_fail.out +++ b/tests/expectations/compiler/expression/cast_fail.out @@ -6,22 +6,22 @@ Error [ETYC0372045]: Strings are not yet supported. | 13 | let b: string = a as string; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Error [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, bool, address`, but got `string` +Error [ETYC0372117]: Expected an integer, bool, field, group, scalar, or address but type `string` was found. --> compiler-test:13:25 | 13 | let b: string = a as string; | ^^^^^^^^^^^ -Error [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, bool, address`, but got `Foo` +Error [ETYC0372117]: Expected an integer, bool, field, group, scalar, or address but type `Foo` was found. --> compiler-test:16:24 | 16 | let d: field = c as field; | ^ -Error [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, bool, address`, but got `(field,field)` +Error [ETYC0372117]: Expected an integer, bool, field, group, scalar, or address but type `(field, field)` was found. --> compiler-test:19:24 | 19 | let f: field = e as field; | ^ -Error [ETYC0372007]: Expected one type from `field, group, scalar, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, bool, address`, but got `(field => field)` +Error [ETYC0372117]: Expected an integer, bool, field, group, scalar, or address but type `(field => field)` was found. --> compiler-test:25:24 | 25 | let b: field = balances as field; diff --git a/tests/expectations/compiler/finalize/finalize_incorrect_return_fail.out b/tests/expectations/compiler/finalize/finalize_incorrect_return_fail.out index c503396ab3..1a1e8e1641 100644 --- a/tests/expectations/compiler/finalize/finalize_incorrect_return_fail.out +++ b/tests/expectations/compiler/finalize/finalize_incorrect_return_fail.out @@ -11,14 +11,9 @@ Error [ETYC0372106]: An async function is not allowed to return a value. | ^ | = Remove an output type in the function signature, and remove the return statement from the function. Note that the future returned by async functions is automatically inferred, and must not be explicitly written. -Error [ETYC0372003]: Expected type `u64` but type `u8` was found +Error [ETYC0372117]: Expected type `u64` but type `u8` was found. --> compiler-test:12:16 | 12 | return 1u8 + 2u8; - | ^^^ -Error [ETYC0372003]: Expected type `u64` but type `u8` was found - --> compiler-test:12:22 - | - 12 | return 1u8 + 2u8; - | ^^^ + | ^^^^^^^^^ """] diff --git a/tests/expectations/compiler/finalize/get_incorrect_type_fail.out b/tests/expectations/compiler/finalize/get_incorrect_type_fail.out index c294aa350e..e43dbf2c94 100644 --- a/tests/expectations/compiler/finalize/get_incorrect_type_fail.out +++ b/tests/expectations/compiler/finalize/get_incorrect_type_fail.out @@ -6,22 +6,22 @@ Error [ETYC0372031]: A mapping's value cannot be a record | 10 | mapping tokens: address => Token; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Error [ETYC0372003]: Expected type `address` but type `bool` was found +Error [ETYC0372117]: Expected type `address` but type `bool` was found. --> compiler-test:17:30 | 17 | Mapping::get(tokens, true); | ^^^^ -Error [ETYC0372003]: Expected type `address` but type `bool` was found +Error [ETYC0372117]: Expected type `address` but type `bool` was found. --> compiler-test:18:20 | 18 | tokens.get(true); | ^^^^ -Error [ETYC0372003]: Expected type `address` but type `u8` was found +Error [ETYC0372117]: Expected type `address` but type `u8` was found. --> compiler-test:19:31 | 19 | Mapping::get(amounts, 1u8); | ^^^ -Error [ETYC0372003]: Expected type `address` but type `u8` was found +Error [ETYC0372117]: Expected type `address` but type `u8` was found. --> compiler-test:20:21 | 20 | amounts.get(1u8); diff --git a/tests/expectations/compiler/finalize/get_or_incorrect_type_fail.out b/tests/expectations/compiler/finalize/get_or_incorrect_type_fail.out index 8c3e666cc6..d8c7192f66 100644 --- a/tests/expectations/compiler/finalize/get_or_incorrect_type_fail.out +++ b/tests/expectations/compiler/finalize/get_or_incorrect_type_fail.out @@ -6,42 +6,42 @@ Error [ETYC0372031]: A mapping's value cannot be a record | 10 | mapping tokens: address => Token; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Error [ETYC0372003]: Expected type `Token` but type `u128` was found +Error [ETYC0372117]: Expected type `Token` but type `u128` was found. --> compiler-test:17:43 | 17 | Mapping::get_or_use(tokens, addr, amount); | ^^^^^^ -Error [ETYC0372003]: Expected type `Token` but type `u128` was found +Error [ETYC0372117]: Expected type `Token` but type `u128` was found. --> compiler-test:18:33 | 18 | tokens.get_or_use(addr, amount); | ^^^^^^ -Error [ETYC0372003]: Expected type `address` but type `u8` was found +Error [ETYC0372117]: Expected type `address` but type `u8` was found. --> compiler-test:19:38 | 19 | Mapping::get_or_use(amounts, 1u8, amount); | ^^^ -Error [ETYC0372003]: Expected type `address` but type `u8` was found +Error [ETYC0372117]: Expected type `address` but type `u8` was found. --> compiler-test:20:28 | 20 | amounts.get_or_use(1u8, amount); | ^^^ -Error [ETYC0372003]: Expected type `u128` but type `u8` was found +Error [ETYC0372117]: Expected type `u128` but type `u8` was found. --> compiler-test:21:44 | 21 | Mapping::get_or_use(amounts, addr, 1u8); | ^^^ -Error [ETYC0372003]: Expected type `u128` but type `u8` was found +Error [ETYC0372117]: Expected type `u128` but type `u8` was found. --> compiler-test:22:34 | 22 | amounts.get_or_use(addr, 1u8); | ^^^ -Error [ETYC0372003]: Expected type `u128` but type `u8` was found +Error [ETYC0372117]: Expected type `u128` but type `u8` was found. --> compiler-test:23:72 | 23 | Mapping::get_or_use(tokens, addr, Token { owner: addr, amount: 1u8 }); | ^^^ -Error [ETYC0372003]: Expected type `u128` but type `u8` was found +Error [ETYC0372117]: Expected type `u128` but type `u8` was found. --> compiler-test:24:62 | 24 | tokens.get_or_use(addr, Token { owner: addr, amount: 1u8 }); diff --git a/tests/expectations/compiler/finalize/rand_incorrect_type_fail.out b/tests/expectations/compiler/finalize/rand_incorrect_type_fail.out index 4b38ec964c..a5b05b0478 100644 --- a/tests/expectations/compiler/finalize/rand_incorrect_type_fail.out +++ b/tests/expectations/compiler/finalize/rand_incorrect_type_fail.out @@ -1,12 +1,12 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `scalar` but type `field` was found +Error [ETYC0372117]: Expected type `scalar` but type `field` was found. --> compiler-test:12:25 | 12 | let a: scalar = ChaCha::rand_field(); | ^^^^^^^^^^^^^^^^^^^^ -Error [ETYC0372003]: Expected type `group` but type `field` was found +Error [ETYC0372117]: Expected type `group` but type `field` was found. --> compiler-test:13:24 | 13 | let b: group = ChaCha::rand_field(); diff --git a/tests/expectations/compiler/finalize/set_in_an_assignment_fail.out b/tests/expectations/compiler/finalize/set_in_an_assignment_fail.out index e7274d7a24..f5dfba8c78 100644 --- a/tests/expectations/compiler/finalize/set_in_an_assignment_fail.out +++ b/tests/expectations/compiler/finalize/set_in_an_assignment_fail.out @@ -6,7 +6,7 @@ Error [ETYC0372055]: The left-hand side of a `DefinitionStatement` can only be a | 11 | let result: () = Mapping::set(amounts, addr, amount); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Error [ETYC0372003]: Expected type `u128` but type `()` was found +Error [ETYC0372117]: Expected type `u128` but type `()` was found. --> compiler-test:12:28 | 12 | let result: u128 = Mapping::set(amounts, addr, amount); diff --git a/tests/expectations/compiler/finalize/set_incorrect_type_fail.out b/tests/expectations/compiler/finalize/set_incorrect_type_fail.out index b9527bc9b2..0a41ca41ea 100644 --- a/tests/expectations/compiler/finalize/set_incorrect_type_fail.out +++ b/tests/expectations/compiler/finalize/set_incorrect_type_fail.out @@ -6,42 +6,42 @@ Error [ETYC0372031]: A mapping's value cannot be a record | 10 | mapping tokens: address => Token; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Error [ETYC0372003]: Expected type `Token` but type `u128` was found +Error [ETYC0372117]: Expected type `Token` but type `u128` was found. --> compiler-test:17:36 | 17 | Mapping::set(tokens, addr, amount); | ^^^^^^ -Error [ETYC0372003]: Expected type `Token` but type `u128` was found +Error [ETYC0372117]: Expected type `Token` but type `u128` was found. --> compiler-test:18:26 | 18 | tokens.set(addr, amount); | ^^^^^^ -Error [ETYC0372003]: Expected type `address` but type `u8` was found +Error [ETYC0372117]: Expected type `address` but type `u8` was found. --> compiler-test:19:31 | 19 | Mapping::set(amounts, 1u8, amount); | ^^^ -Error [ETYC0372003]: Expected type `address` but type `u8` was found +Error [ETYC0372117]: Expected type `address` but type `u8` was found. --> compiler-test:20:21 | 20 | amounts.set(1u8, amount); | ^^^ -Error [ETYC0372003]: Expected type `u128` but type `u8` was found +Error [ETYC0372117]: Expected type `u128` but type `u8` was found. --> compiler-test:21:37 | 21 | Mapping::set(amounts, addr, 1u8); | ^^^ -Error [ETYC0372003]: Expected type `u128` but type `u8` was found +Error [ETYC0372117]: Expected type `u128` but type `u8` was found. --> compiler-test:22:27 | 22 | amounts.set(addr, 1u8); | ^^^ -Error [ETYC0372003]: Expected type `u128` but type `u8` was found +Error [ETYC0372117]: Expected type `u128` but type `u8` was found. --> compiler-test:23:65 | 23 | Mapping::set(tokens, addr, Token { owner: addr, amount: 1u8 }); | ^^^ -Error [ETYC0372003]: Expected type `u128` but type `u8` was found +Error [ETYC0372117]: Expected type `u128` but type `u8` was found. --> compiler-test:24:55 | 24 | tokens.set(addr, Token { owner: addr, amount: 1u8 }); diff --git a/tests/expectations/compiler/function/function_call_tyc_fail.out b/tests/expectations/compiler/function/function_call_tyc_fail.out index a664f96754..c97e517cd3 100644 --- a/tests/expectations/compiler/function/function_call_tyc_fail.out +++ b/tests/expectations/compiler/function/function_call_tyc_fail.out @@ -11,7 +11,7 @@ Error [ETYC0372003]: Expected type `i8` but type `u8` was found | 20 | y = f3(y, z); | ^^^^^^^^ -Error [ETYC0372003]: Expected type `u8` but type `i8` was found +Error [ETYC0372117]: Expected type `u8` but type `i8` was found. --> compiler-test:20:16 | 20 | y = f3(y, z); diff --git a/tests/expectations/compiler/function/self_fail.out b/tests/expectations/compiler/function/self_fail.out index 971acb4ea9..eeebe6ec96 100644 --- a/tests/expectations/compiler/function/self_fail.out +++ b/tests/expectations/compiler/function/self_fail.out @@ -6,9 +6,4 @@ Error [ETYC0372040]: The allowed accesses to `self` are `self.caller` and `self. | 5 | return self.foo == addr; | ^^^ -Error [ETYC0372003]: Expected type `address` but type `no type` was found - --> compiler-test:5:16 - | - 5 | return self.foo == addr; - | ^^^^^^^^^^^^^^^^ """] diff --git a/tests/expectations/compiler/function/unknown_parameter_type_fail.out b/tests/expectations/compiler/function/unknown_parameter_type_fail.out index e7e1376626..fc6d83209b 100644 --- a/tests/expectations/compiler/function/unknown_parameter_type_fail.out +++ b/tests/expectations/compiler/function/unknown_parameter_type_fail.out @@ -15,7 +15,7 @@ Error [ETYC0372017]: The type `Foo` is not found in the current scope. | ^^^ | = If you are using an external type, make sure to preface with the program name. Ex: `credits.aleo/credits` instead of `credits` -Error [ETYC0372003]: Expected type `Foo` but type `u8` was found +Error [ETYC0372117]: Expected type `Foo` but type `u8` was found. --> compiler-test:9:16 | 9 | return a; diff --git a/tests/expectations/compiler/futures/async_before_call_fail.out b/tests/expectations/compiler/futures/async_before_call_fail.out new file mode 100644 index 0000000000..5dc665f10a --- /dev/null +++ b/tests/expectations/compiler/futures/async_before_call_fail.out @@ -0,0 +1,11 @@ +namespace = "Compile" +expectation = "Fail" +outputs = [""" +Error [ETYC0372102]: External transition calls cannot be made after local async function call + --> compiler-test:8:9 + | + 8 | child.aleo/t(); + | ^^^^^^^^^^^^^^ + | + = Move the async function call before the transition call. +"""] diff --git a/tests/expectations/compiler/group/mult_by_group_fail.out b/tests/expectations/compiler/group/mult_by_group_fail.out index 685375e5f1..6984add261 100644 --- a/tests/expectations/compiler/group/mult_by_group_fail.out +++ b/tests/expectations/compiler/group/mult_by_group_fail.out @@ -1,11 +1,13 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372007]: Expected one type from `scalar`, but got `group` - --> compiler-test:5:30 +Error [ETYC0372120]: Received types `group` and `group` for the operation `*`. + --> compiler-test:5:16 | 5 | return (_, _)group * a; - | ^ + | ^^^^^^^^^^^^^^^ + | + = Valid operands are two integers of the same type, two fields, or a scalar and a group. Error [ETYC0372083]: A program must have at least one transition function. --> compiler-test:1:1 | diff --git a/tests/expectations/compiler/mappings/variable_shadow_mapping_fail.out b/tests/expectations/compiler/mappings/variable_shadow_mapping_fail.out index 728171d9b8..74b1b7189f 100644 --- a/tests/expectations/compiler/mappings/variable_shadow_mapping_fail.out +++ b/tests/expectations/compiler/mappings/variable_shadow_mapping_fail.out @@ -6,7 +6,7 @@ Error [EAST0372009]: variable `m` shadowed by | 7 | let m: u8 = 1u8; | ^ -Error [ETYC0372003]: Expected type `u8` but type `(u8 => u8)` was found +Error [ETYC0372117]: Expected type `u8` but type `(u8 => u8)` was found. --> compiler-test:8:16 | 8 | return m; diff --git a/tests/expectations/compiler/operations/abs_type_fail.out b/tests/expectations/compiler/operations/abs_type_fail.out new file mode 100644 index 0000000000..40cd24ddcc --- /dev/null +++ b/tests/expectations/compiler/operations/abs_type_fail.out @@ -0,0 +1,14 @@ +namespace = "Compile" +expectation = "Fail" +outputs = [""" +Error [ETYC0372117]: Expected a signed integer but type `u16` was found. + --> compiler-test:5:24 + | + 5 | return (true ? 1u16.abs() : 2u16.abs()) as u8; + | ^^^^^^^^^^ +Error [ETYC0372117]: Expected a signed integer but type `u16` was found. + --> compiler-test:5:37 + | + 5 | return (true ? 1u16.abs() : 2u16.abs()) as u8; + | ^^^^^^^^^^ +"""] diff --git a/tests/expectations/compiler/operations/add_type_fail.out b/tests/expectations/compiler/operations/add_type_fail.out new file mode 100644 index 0000000000..3cfe1acea2 --- /dev/null +++ b/tests/expectations/compiler/operations/add_type_fail.out @@ -0,0 +1,14 @@ +namespace = "Compile" +expectation = "Fail" +outputs = [""" +Error [ETYC0372117]: Expected a field, group, scalar, or integer but type `bool` was found. + --> compiler-test:5:17 + | + 5 | return (true + false) as u8; + | ^^^^ +Error [ETYC0372117]: Expected a field, group, scalar, or integer but type `bool` was found. + --> compiler-test:5:24 + | + 5 | return (true + false) as u8; + | ^^^^^ +"""] diff --git a/tests/expectations/compiler/records/duplicate_circuit_name_fail.out b/tests/expectations/compiler/records/duplicate_circuit_name_fail.out index 2813782684..1d318eb21a 100644 --- a/tests/expectations/compiler/records/duplicate_circuit_name_fail.out +++ b/tests/expectations/compiler/records/duplicate_circuit_name_fail.out @@ -1,11 +1,11 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372083]: A program must have at least one transition function. - --> compiler-test:1:1 +Error [EAST0372008]: record `Token` shadowed by + --> compiler-test:11:5 | - 1 | - 2 | - 3 | program test.aleo { - | ^^^^^^^^^^^^ + 11 | struct Token { // This struct cannot have the same name as the record defined above it. + 12 | x: u32, + 13 | } + | ^ """] diff --git a/tests/expectations/compiler/records/init_expression_type_fail.out b/tests/expectations/compiler/records/init_expression_type_fail.out index 35997f01e3..6059ec5ce9 100644 --- a/tests/expectations/compiler/records/init_expression_type_fail.out +++ b/tests/expectations/compiler/records/init_expression_type_fail.out @@ -11,12 +11,12 @@ Error [ETYC0372057]: Only `transition` functions can have a record as input or o | 11 | function mint(r0: address, r1: u64) -> Token { | ^^^^^ -Error [ETYC0372003]: Expected type `address` but type `u64` was found +Error [ETYC0372117]: Expected type `address` but type `u64` was found. --> compiler-test:13:20 | 13 | owner: r1, // This variable should be type address. | ^^ -Error [ETYC0372003]: Expected type `u64` but type `address` was found +Error [ETYC0372117]: Expected type `u64` but type `address` was found. --> compiler-test:14:21 | 14 | amount: r0, // This variable should be type u64. diff --git a/tests/expectations/compiler/records/same_name_diff_type_fail.out b/tests/expectations/compiler/records/same_name_diff_type_fail.out new file mode 100644 index 0000000000..4233f2b1a7 --- /dev/null +++ b/tests/expectations/compiler/records/same_name_diff_type_fail.out @@ -0,0 +1,11 @@ +namespace = "Compile" +expectation = "Fail" +outputs = [""" +Error [ETYC0372119]: Received different types `R` and `R` for the operation `==`. + --> compiler-test:16:16 + | + 16 | return r1 == child.aleo/create(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = Make both operands the same type. +"""] diff --git a/tests/expectations/compiler/scalar/div_fail.out b/tests/expectations/compiler/scalar/div_fail.out index 5dfacd4812..8cb218346e 100644 --- a/tests/expectations/compiler/scalar/div_fail.out +++ b/tests/expectations/compiler/scalar/div_fail.out @@ -1,11 +1,16 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372007]: Expected one type from `field, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128`, but got `scalar` +Error [ETYC0372117]: Expected a field or integer but type `scalar` was found. --> compiler-test:5:16 | 5 | return a / b; // division not supported for scalar types. - | ^^^^^ + | ^ +Error [ETYC0372117]: Expected a field or integer but type `scalar` was found. + --> compiler-test:5:20 + | + 5 | return a / b; // division not supported for scalar types. + | ^ Error [ETYC0372083]: A program must have at least one transition function. --> compiler-test:1:1 | diff --git a/tests/expectations/compiler/scalar/square_root_fail.out b/tests/expectations/compiler/scalar/square_root_fail.out index 88efaf977e..879d11dc37 100644 --- a/tests/expectations/compiler/scalar/square_root_fail.out +++ b/tests/expectations/compiler/scalar/square_root_fail.out @@ -1,7 +1,7 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372007]: Expected one type from `field`, but got `scalar` +Error [ETYC0372117]: Expected type `field` but type `scalar` was found. --> compiler-test:5:16 | 5 | return a.square_root(); // square root not supported for scalar types. diff --git a/tests/expectations/compiler/signature/signature_with_wrong_types_fail.out b/tests/expectations/compiler/signature/signature_with_wrong_types_fail.out index 9afa684db7..faeac51441 100644 --- a/tests/expectations/compiler/signature/signature_with_wrong_types_fail.out +++ b/tests/expectations/compiler/signature/signature_with_wrong_types_fail.out @@ -1,32 +1,32 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372007]: Expected one type from `signature`, but got `address` +Error [ETYC0372117]: Expected type `signature` but type `address` was found. --> compiler-test:11:45 | 11 | let first: bool = signature::verify(a, s, v); | ^ -Error [ETYC0372007]: Expected one type from `address`, but got `signature` +Error [ETYC0372117]: Expected type `address` but type `signature` was found. --> compiler-test:11:48 | 11 | let first: bool = signature::verify(a, s, v); | ^ -Error [ETYC0372007]: Expected one type from `address`, but got `u8` +Error [ETYC0372117]: Expected type `address` but type `u8` was found. --> compiler-test:12:37 | 12 | let second: bool = s.verify(1u8, v); | ^^^ -Error [ETYC0372007]: Expected one type from `signature`, but got `address` +Error [ETYC0372117]: Expected type `signature` but type `address` was found. --> compiler-test:17:45 | 17 | let first: bool = signature::verify(a, v, s); | ^ -Error [ETYC0372007]: Expected one type from `address`, but got `foo` +Error [ETYC0372117]: Expected type `address` but type `foo` was found. --> compiler-test:17:48 | 17 | let first: bool = signature::verify(a, v, s); | ^ -Error [ETYC0372007]: Expected one type from `address`, but got `foo` +Error [ETYC0372117]: Expected type `address` but type `foo` was found. --> compiler-test:18:37 | 18 | let second: bool = s.verify(v, a); diff --git a/tests/expectations/compiler/statements/assign_ternary.out b/tests/expectations/compiler/statements/assign_ternary.out index 1beb8aec8b..349ea9a00b 100644 --- a/tests/expectations/compiler/statements/assign_ternary.out +++ b/tests/expectations/compiler/statements/assign_ternary.out @@ -1,11 +1,18 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `bool` but type `u32` was found +Error [ETYC0372117]: Expected type `bool` but type `u32` was found. --> compiler-test:5:30 | 5 | let x: bool = true ? x: true; | ^ +Error [ETYC0372118]: Received different types `u32` and `bool` for the arms of a ternary conditional. + --> compiler-test:5:23 + | + 5 | let x: bool = true ? x: true; + | ^^^^^^^^^^^^^^ + | + = Make both branches the same type. Error [EAST0372009]: variable `x` shadowed by --> compiler-test:5:13 | diff --git a/tests/expectations/compiler/statements/compare_diff_types_fail.out b/tests/expectations/compiler/statements/compare_diff_types_fail.out index e2f8403416..93f221a0ef 100644 --- a/tests/expectations/compiler/statements/compare_diff_types_fail.out +++ b/tests/expectations/compiler/statements/compare_diff_types_fail.out @@ -1,46 +1,55 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `u8` but type `i8` was found +Error [ETYC0372119]: Received different types `i8` and `u8` for the operation `==`. --> compiler-test:5:23 | 5 | let b: bool = a == 1u8; | ^^^^^^^^ -Error [ETYC0372003]: Expected type `u8` but type `i8` was found + | + = Make both operands the same type. +Error [ETYC0372119]: Received different types `i8` and `u8` for the operation `!=`. --> compiler-test:6:23 | 6 | let c: bool = a != 1u8; | ^^^^^^^^ -Error [ETYC0372003]: Expected type `u8` but type `i8` was found + | + = Make both operands the same type. +Error [ETYC0372119]: Received different types `i8` and `u8` for the operation `>`. --> compiler-test:7:23 | 7 | let d: bool = a > 1u8; | ^^^^^^^ -Error [ETYC0372003]: Expected type `u8` but type `i8` was found + | + = Make both operands the same type. +Error [ETYC0372119]: Received different types `i8` and `u8` for the operation `<`. --> compiler-test:8:23 | 8 | let e: bool = a < 1u8; | ^^^^^^^ -Error [ETYC0372003]: Expected type `u8` but type `i8` was found + | + = Make both operands the same type. +Error [ETYC0372119]: Received different types `i8` and `u8` for the operation `>=`. --> compiler-test:9:23 | 9 | let f: bool = a >= 1u8; | ^^^^^^^^ -Error [ETYC0372003]: Expected type `u8` but type `i8` was found + | + = Make both operands the same type. +Error [ETYC0372119]: Received different types `i8` and `u8` for the operation `<=`. --> compiler-test:10:23 | 10 | let g: bool = a <= 1u8; | ^^^^^^^^ -Error [ETYC0372003]: Expected type `i8` but type `u8` was found - --> compiler-test:11:26 | - 11 | let h: u32 = a * 1u8; - | ^^^ -Error [ETYC0372003]: Expected type `i8` but type `u32` was found + = Make both operands the same type. +Error [ETYC0372120]: Received types `i8` and `u8` for the operation `*`. --> compiler-test:11:22 | 11 | let h: u32 = a * 1u8; | ^^^^^^^ + | + = Valid operands are two integers of the same type, two fields, or a scalar and a group. Error [ETYC0372083]: A program must have at least one transition function. --> compiler-test:1:1 | diff --git a/tests/expectations/compiler/statements/compare_invalid_negates_fail.out b/tests/expectations/compiler/statements/compare_invalid_negates_fail.out index 6cf2387c7c..868ddec12b 100644 --- a/tests/expectations/compiler/statements/compare_invalid_negates_fail.out +++ b/tests/expectations/compiler/statements/compare_invalid_negates_fail.out @@ -1,71 +1,36 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372007]: Expected one type from `field, group, i8, i16, i32, i64, i128`, but got `u8` - --> compiler-test:5:24 - | - 5 | let b: bool = -a == -1u8; - | ^ Error [ETYC0372008]: The value -1 is not a valid `u8` --> compiler-test:5:29 | 5 | let b: bool = -a == -1u8; | ^^^^ -Error [ETYC0372007]: Expected one type from `field, group, i8, i16, i32, i64, i128`, but got `u8` - --> compiler-test:6:24 - | - 6 | let c: bool = -a > -1u8; - | ^ Error [ETYC0372008]: The value -1 is not a valid `u8` --> compiler-test:6:28 | 6 | let c: bool = -a > -1u8; | ^^^^ -Error [ETYC0372007]: Expected one type from `field, group, i8, i16, i32, i64, i128`, but got `u8` - --> compiler-test:7:24 - | - 7 | let d: bool = -a < -1u8; - | ^ Error [ETYC0372008]: The value -1 is not a valid `u8` --> compiler-test:7:28 | 7 | let d: bool = -a < -1u8; | ^^^^ -Error [ETYC0372007]: Expected one type from `field, group, i8, i16, i32, i64, i128`, but got `u8` - --> compiler-test:8:24 - | - 8 | let e: bool = -a >= -1u8; - | ^ Error [ETYC0372008]: The value -1 is not a valid `u8` --> compiler-test:8:29 | 8 | let e: bool = -a >= -1u8; | ^^^^ -Error [ETYC0372007]: Expected one type from `field, group, i8, i16, i32, i64, i128`, but got `u8` - --> compiler-test:9:24 - | - 9 | let f: bool = -a <= -1u8; - | ^ Error [ETYC0372008]: The value -1 is not a valid `u8` --> compiler-test:9:29 | 9 | let f: bool = -a <= -1u8; | ^^^^ -Error [ETYC0372007]: Expected one type from `field, group, i8, i16, i32, i64, i128`, but got `u8` - --> compiler-test:10:22 - | - 10 | let g: u8 = -a * -1u8; - | ^ Error [ETYC0372008]: The value -1 is not a valid `u8` --> compiler-test:10:26 | 10 | let g: u8 = -a * -1u8; | ^^^^ -Error [ETYC0372007]: Expected one type from `field, group, i8, i16, i32, i64, i128`, but got `u8` - --> compiler-test:11:22 - | - 11 | let h: u8 = -a ** -1u8; - | ^ Error [ETYC0372008]: The value -1 is not a valid `u8` --> compiler-test:11:27 | diff --git a/tests/expectations/compiler/statements/non_existant_vars_mul_fail.out b/tests/expectations/compiler/statements/non_existant_vars_mul_fail.out index 303529f5d8..f73fc26105 100644 --- a/tests/expectations/compiler/statements/non_existant_vars_mul_fail.out +++ b/tests/expectations/compiler/statements/non_existant_vars_mul_fail.out @@ -11,16 +11,6 @@ Error [ETYC0372005]: Unknown variable `z` | 5 | \tlet b: u8 = x*z; | ^ -Error [ETYC0372004]: Could not determine the type of `x` - --> compiler-test:5:18 - | - 5 | \tlet b: u8 = x*z; - | ^ -Error [ETYC0372004]: Could not determine the type of `z` - --> compiler-test:5:20 - | - 5 | \tlet b: u8 = x*z; - | ^ Error [ETYC0372083]: A program must have at least one transition function. --> compiler-test:1:1 | diff --git a/tests/expectations/compiler/statements/typecheck_statements_fail.out b/tests/expectations/compiler/statements/typecheck_statements_fail.out index a80d0d89f4..c7540b93b6 100644 --- a/tests/expectations/compiler/statements/typecheck_statements_fail.out +++ b/tests/expectations/compiler/statements/typecheck_statements_fail.out @@ -1,41 +1,30 @@ namespace = "Compile" expectation = "Fail" outputs = [''' -Error [ETYC0372003]: Expected type `i16` but type `i32` was found - --> compiler-test:5:33 - | - 5 | let c1 : u32 = 123i16 * 123i32; - | ^^^^^^ -Error [ETYC0372003]: Expected type `i16` but type `u32` was found +Error [ETYC0372120]: Received types `i16` and `i32` for the operation `*`. --> compiler-test:5:24 | 5 | let c1 : u32 = 123i16 * 123i32; | ^^^^^^^^^^^^^^^ + | + = Valid operands are two integers of the same type, two fields, or a scalar and a group. Error [ETYC0372045]: Strings are not yet supported. --> compiler-test:6:24 | 6 | let c2 : u32 = "123i32" * 123i16 * "sss"; | ^^^^^^^^ -Error [ETYC0372003]: Expected type `i16` but type `string` was found +Error [ETYC0372120]: Received types `string` and `i16` for the operation `*`. --> compiler-test:6:24 | 6 | let c2 : u32 = "123i32" * 123i16 * "sss"; - | ^^^^^^^^ -Error [ETYC0372045]: Strings are not yet supported. - --> compiler-test:6:44 + | ^^^^^^^^^^^^^^^^^ | - 6 | let c2 : u32 = "123i32" * 123i16 * "sss"; - | ^^^^^ -Error [ETYC0372003]: Expected type `i16` but type `string` was found + = Valid operands are two integers of the same type, two fields, or a scalar and a group. +Error [ETYC0372045]: Strings are not yet supported. --> compiler-test:6:44 | 6 | let c2 : u32 = "123i32" * 123i16 * "sss"; | ^^^^^ -Error [ETYC0372003]: Expected type `i16` but type `u32` was found - --> compiler-test:6:24 - | - 6 | let c2 : u32 = "123i32" * 123i16 * "sss"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ Error [ETYC0372045]: Strings are not yet supported. --> compiler-test:7:24 | @@ -46,84 +35,52 @@ Error [ETYC0372045]: Strings are not yet supported. | 7 | let c3 : u32 = "123i32" * "sss"; | ^^^^^ -Error [ETYC0372003]: Expected type `field, group, integer, or scalar` but type `string` was found +Error [ETYC0372120]: Received types `string` and `string` for the operation `*`. --> compiler-test:7:24 | 7 | let c3 : u32 = "123i32" * "sss"; - | ^^^^^^^^ -Error [ETYC0372003]: Expected type `field, group, integer, or scalar` but type `string` was found - --> compiler-test:7:35 - | - 7 | let c3 : u32 = "123i32" * "sss"; - | ^^^^^ -Error [ETYC0372003]: Expected type `i8` but type `i16` was found - --> compiler-test:8:30 - | - 8 | let c4 : u32 = 1i8 * 2i16 * 3i32 * 4i64 * 5u8 * 6u16 * 7u32 * 9u64; - | ^^^^ -Error [ETYC0372003]: Expected type `i8` but type `i32` was found - --> compiler-test:8:37 - | - 8 | let c4 : u32 = 1i8 * 2i16 * 3i32 * 4i64 * 5u8 * 6u16 * 7u32 * 9u64; - | ^^^^ -Error [ETYC0372003]: Expected type `i8` but type `i64` was found - --> compiler-test:8:44 + | ^^^^^^^^^^^^^^^^ | - 8 | let c4 : u32 = 1i8 * 2i16 * 3i32 * 4i64 * 5u8 * 6u16 * 7u32 * 9u64; - | ^^^^ -Error [ETYC0372003]: Expected type `i8` but type `u8` was found - --> compiler-test:8:51 - | - 8 | let c4 : u32 = 1i8 * 2i16 * 3i32 * 4i64 * 5u8 * 6u16 * 7u32 * 9u64; - | ^^^ -Error [ETYC0372003]: Expected type `i8` but type `u16` was found - --> compiler-test:8:57 - | - 8 | let c4 : u32 = 1i8 * 2i16 * 3i32 * 4i64 * 5u8 * 6u16 * 7u32 * 9u64; - | ^^^^ -Error [ETYC0372003]: Expected type `i8` but type `u32` was found - --> compiler-test:8:64 - | - 8 | let c4 : u32 = 1i8 * 2i16 * 3i32 * 4i64 * 5u8 * 6u16 * 7u32 * 9u64; - | ^^^^ -Error [ETYC0372003]: Expected type `i8` but type `u64` was found - --> compiler-test:8:71 - | - 8 | let c4 : u32 = 1i8 * 2i16 * 3i32 * 4i64 * 5u8 * 6u16 * 7u32 * 9u64; - | ^^^^ -Error [ETYC0372003]: Expected type `i8` but type `u32` was found + = Valid operands are two integers of the same type, two fields, or a scalar and a group. +Error [ETYC0372120]: Received types `i8` and `i16` for the operation `*`. --> compiler-test:8:24 | 8 | let c4 : u32 = 1i8 * 2i16 * 3i32 * 4i64 * 5u8 * 6u16 * 7u32 * 9u64; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ + | + = Valid operands are two integers of the same type, two fields, or a scalar and a group. Error [ETYC0372045]: Strings are not yet supported. --> compiler-test:9:26 | 9 | let c16: bool = ("123i32" & 123i16) == ("sss" / 1i8 - 1i8 + 22u32); | ^^^^^^^^ -Error [ETYC0372003]: Expected type `i16` but type `string` was found +Error [ETYC0372117]: Expected a bool or integer but type `string` was found. + --> compiler-test:9:26 + | + 9 | let c16: bool = ("123i32" & 123i16) == ("sss" / 1i8 - 1i8 + 22u32); + | ^^^^^^^^ +Error [ETYC0372119]: Received different types `string` and `i16` for the operation `&`. --> compiler-test:9:26 | 9 | let c16: bool = ("123i32" & 123i16) == ("sss" / 1i8 - 1i8 + 22u32); | ^^^^^^^^^^^^^^^^^ + | + = Make both operands the same type. Error [ETYC0372045]: Strings are not yet supported. --> compiler-test:9:49 | 9 | let c16: bool = ("123i32" & 123i16) == ("sss" / 1i8 - 1i8 + 22u32); | ^^^^^ -Error [ETYC0372003]: Expected type `i8` but type `string` was found +Error [ETYC0372117]: Expected a field or integer but type `string` was found. --> compiler-test:9:49 | 9 | let c16: bool = ("123i32" & 123i16) == ("sss" / 1i8 - 1i8 + 22u32); - | ^^^^^^^^^^^ -Error [ETYC0372003]: Expected type `i8` but type `string` was found + | ^^^^^ +Error [ETYC0372119]: Received different types `string` and `i8` for the operation `/`. --> compiler-test:9:49 | 9 | let c16: bool = ("123i32" & 123i16) == ("sss" / 1i8 - 1i8 + 22u32); - | ^^^^^^^^^^^^^^^^^ -Error [ETYC0372003]: Expected type `u32` but type `string` was found - --> compiler-test:9:49 + | ^^^^^^^^^^^ | - 9 | let c16: bool = ("123i32" & 123i16) == ("sss" / 1i8 - 1i8 + 22u32); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = Make both operands the same type. '''] diff --git a/tests/expectations/compiler/statements/unknown_type_in_definition_fail.out b/tests/expectations/compiler/statements/unknown_type_in_definition_fail.out index 33d0853344..166788f42e 100644 --- a/tests/expectations/compiler/statements/unknown_type_in_definition_fail.out +++ b/tests/expectations/compiler/statements/unknown_type_in_definition_fail.out @@ -8,7 +8,7 @@ Error [ETYC0372017]: The type `Foo` is not found in the current scope. | ^^^^^^^^^^^^^^^^ | = If you are using an external type, make sure to preface with the program name. Ex: `credits.aleo/credits` instead of `credits` -Error [ETYC0372003]: Expected type `Foo` but type `u8` was found +Error [ETYC0372117]: Expected type `Foo` but type `u8` was found. --> compiler-test:5:19 | 5 | \tlet b: Foo = 1u8; diff --git a/tests/expectations/compiler/structs/struct_access_fail.out b/tests/expectations/compiler/structs/struct_access_fail.out index ffa1658d1f..4f84e3c134 100644 --- a/tests/expectations/compiler/structs/struct_access_fail.out +++ b/tests/expectations/compiler/structs/struct_access_fail.out @@ -1,7 +1,7 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `i8` but type `u32` was found +Error [ETYC0372117]: Expected type `i8` but type `u32` was found. --> compiler-test:11:21 | 11 | let x: i8 = s.f1; diff --git a/tests/expectations/compiler/ternary/ternary_mismatch_fail.out b/tests/expectations/compiler/ternary/ternary_mismatch_fail.out new file mode 100644 index 0000000000..8cfea3d771 --- /dev/null +++ b/tests/expectations/compiler/ternary/ternary_mismatch_fail.out @@ -0,0 +1,11 @@ +namespace = "Compile" +expectation = "Fail" +outputs = [""" +Error [ETYC0372118]: Received different types `u8` and `u16` for the arms of a ternary conditional. + --> compiler-test:5:17 + | + 5 | return (true ? 1u8 : 1u16) as u32; + | ^^^^^^^^^^^^^^^^^ + | + = Make both branches the same type. +"""] diff --git a/tests/expectations/compiler/tuple/access_out_of_bounds_fail.out b/tests/expectations/compiler/tuple/access_out_of_bounds_fail.out index 9577dc7db5..2a80930d9f 100644 --- a/tests/expectations/compiler/tuple/access_out_of_bounds_fail.out +++ b/tests/expectations/compiler/tuple/access_out_of_bounds_fail.out @@ -6,11 +6,6 @@ Error [ETYC0372024]: Tuple index `2` out of range for a tuple with length `2` | 7 | return (t.0, t.2); // Index `t.2` is out of bounds. | ^ -Error [ETYC0372014]: t.2 is not a valid core function call. - --> compiler-test:7:24 - | - 7 | return (t.0, t.2); // Index `t.2` is out of bounds. - | ^ Error [ETYC0372083]: A program must have at least one transition function. --> compiler-test:1:1 | diff --git a/tests/expectations/compiler/tuple/declare_fail.out b/tests/expectations/compiler/tuple/declare_fail.out index e71d8ac63f..4a1f0196f4 100644 --- a/tests/expectations/compiler/tuple/declare_fail.out +++ b/tests/expectations/compiler/tuple/declare_fail.out @@ -1,7 +1,7 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `bool` but type `u64` was found +Error [ETYC0372117]: Expected type `bool` but type `u64` was found. --> compiler-test:5:35 | 5 | let t: (bool, bool) = (a, 1u64); // We should be declaring to a bool, not a u64. diff --git a/tests/expectations/compiler/tuple/return_statement_fail.out b/tests/expectations/compiler/tuple/return_statement_fail.out index 50c001715f..a0e08a2e29 100644 --- a/tests/expectations/compiler/tuple/return_statement_fail.out +++ b/tests/expectations/compiler/tuple/return_statement_fail.out @@ -1,7 +1,7 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `u64` but type `bool` was found +Error [ETYC0372117]: Expected type `u64` but type `bool` was found. --> compiler-test:7:24 | 7 | return (t.0, t.1); // The second element should be type u64 as in the function declaration. diff --git a/tests/expectations/compiler/tuple/tuple_not_allowed_fail.out b/tests/expectations/compiler/tuple/tuple_not_allowed_fail.out index b8bb0647fe..cd2d78c7b0 100644 --- a/tests/expectations/compiler/tuple/tuple_not_allowed_fail.out +++ b/tests/expectations/compiler/tuple/tuple_not_allowed_fail.out @@ -26,17 +26,17 @@ Error [ETYC0372052]: A tuple expression cannot contain another tuple expression. | 13 | return (1u8, (2u16, 3u32)); | ^^^^^^^^^^^^ -Error [ETYC0372007]: Expected one type from `i8, i16, i32, i64, i128, u8, u16, u32, u64, u128`, but got `(u8,u16)` +Error [ETYC0372117]: Expected an integer but type `(u8, u16)` was found. --> compiler-test:17:13 | 17 | for i: (u8, u16) in 0u8..2u8 {} | ^ -Error [ETYC0372003]: Expected type `(u8,u16)` but type `u8` was found +Error [ETYC0372117]: Expected type `(u8, u16)` but type `u8` was found. --> compiler-test:17:29 | 17 | for i: (u8, u16) in 0u8..2u8 {} | ^^^ -Error [ETYC0372003]: Expected type `(u8,u16)` but type `u8` was found +Error [ETYC0372117]: Expected type `(u8, u16)` but type `u8` was found. --> compiler-test:17:34 | 17 | for i: (u8, u16) in 0u8..2u8 {} diff --git a/tests/expectations/compiler/tuple/type_fail.out b/tests/expectations/compiler/tuple/type_fail.out index da139bbac0..9b48b53dbf 100644 --- a/tests/expectations/compiler/tuple/type_fail.out +++ b/tests/expectations/compiler/tuple/type_fail.out @@ -1,12 +1,12 @@ namespace = "Compile" expectation = "Fail" outputs = [""" -Error [ETYC0372003]: Expected type `u64` but type `bool` was found +Error [ETYC0372117]: Expected type `u64` but type `bool` was found. --> compiler-test:5:34 | 5 | let t: (bool, u64) = (a, b); // We should expect a bool, not a u64. | ^ -Error [ETYC0372003]: Expected type `bool` but type `u64` was found +Error [ETYC0372117]: Expected type `bool` but type `u64` was found. --> compiler-test:7:24 | 7 | return (t.0, t.1); diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i128.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i128.leo index 4f8b25c87f..9baa36abd2 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i128.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i128.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i16.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i16.leo index cf6d008782..96851d4eae 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i16.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i16.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i32.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i32.leo index 1641fafde5..6e95757e56 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i32.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i32.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i64.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i64.leo index 4999280d03..2b08650f5a 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i64.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i64.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i8.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i8.leo index db6d1ef8ed..56adf2dda6 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i8.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_i8.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u128.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u128.leo index a8fec57862..506c8749f2 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u128.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u128.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u16.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u16.leo index d62473a4b6..efa9b83603 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u16.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u16.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u32.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u32.leo index 042e75ae82..1ef1bcd495 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u32.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u32.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u64.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u64.leo index dd9da9b83e..1630d2f0c8 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u64.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u64.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u8.leo b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u8.leo index 2e2013d54a..16fbca3773 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u8.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen128/pedersen128_hash_to_u8.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i128.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i128.leo index 3aa6aa0ff0..3d477198a2 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i128.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i128.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i16.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i16.leo index 9d7178dc84..32e7112121 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i16.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i16.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i32.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i32.leo index 5f50677a43..67059d5cc9 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i32.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i32.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i64.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i64.leo index 1895870269..1b74cadd01 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i64.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i64.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i8.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i8.leo index 37b4d26edd..3e9fbc3889 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i8.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_i8.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u128.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u128.leo index cf1330e41e..520c8c3e49 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u128.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u128.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u16.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u16.leo index b41e54c79f..ed2101763e 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u16.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u16.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u32.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u32.leo index 1385c21856..f20f105a88 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u32.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u32.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u64.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u64.leo index 3867c486f8..9ae76f7e7d 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u64.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u64.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u8.leo b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u8.leo index 997a7c707e..ca12a5ab3b 100644 --- a/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u8.leo +++ b/tests/tests/compiler/core/algorithms/integers/pedersen64/pedersen64_hash_to_u8.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen128_commit_to_address.leo b/tests/tests/compiler/core/algorithms/pedersen128_commit_to_address.leo index a906ceb39c..d1f0c4947c 100644 --- a/tests/tests/compiler/core/algorithms/pedersen128_commit_to_address.leo +++ b/tests/tests/compiler/core/algorithms/pedersen128_commit_to_address.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen128_commit_to_field.leo b/tests/tests/compiler/core/algorithms/pedersen128_commit_to_field.leo index b7fb885aae..263224ba4d 100644 --- a/tests/tests/compiler/core/algorithms/pedersen128_commit_to_field.leo +++ b/tests/tests/compiler/core/algorithms/pedersen128_commit_to_field.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen128_commit_to_group.leo b/tests/tests/compiler/core/algorithms/pedersen128_commit_to_group.leo index 94b36e5a20..3a777b847d 100644 --- a/tests/tests/compiler/core/algorithms/pedersen128_commit_to_group.leo +++ b/tests/tests/compiler/core/algorithms/pedersen128_commit_to_group.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen128_hash_to_address.leo b/tests/tests/compiler/core/algorithms/pedersen128_hash_to_address.leo index 9dddbdea41..528ded18a1 100644 --- a/tests/tests/compiler/core/algorithms/pedersen128_hash_to_address.leo +++ b/tests/tests/compiler/core/algorithms/pedersen128_hash_to_address.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen128_hash_to_field.leo b/tests/tests/compiler/core/algorithms/pedersen128_hash_to_field.leo index 27c89acc35..dbe0ba9168 100644 --- a/tests/tests/compiler/core/algorithms/pedersen128_hash_to_field.leo +++ b/tests/tests/compiler/core/algorithms/pedersen128_hash_to_field.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen128_hash_to_group.leo b/tests/tests/compiler/core/algorithms/pedersen128_hash_to_group.leo index 8a64234b3c..e591f8f19a 100644 --- a/tests/tests/compiler/core/algorithms/pedersen128_hash_to_group.leo +++ b/tests/tests/compiler/core/algorithms/pedersen128_hash_to_group.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen64_commit_to_address.leo b/tests/tests/compiler/core/algorithms/pedersen64_commit_to_address.leo index c36d479e7d..fda7525c27 100644 --- a/tests/tests/compiler/core/algorithms/pedersen64_commit_to_address.leo +++ b/tests/tests/compiler/core/algorithms/pedersen64_commit_to_address.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen64_commit_to_field.leo b/tests/tests/compiler/core/algorithms/pedersen64_commit_to_field.leo index e885c33ad1..ac20ac27ec 100644 --- a/tests/tests/compiler/core/algorithms/pedersen64_commit_to_field.leo +++ b/tests/tests/compiler/core/algorithms/pedersen64_commit_to_field.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen64_commit_to_group.leo b/tests/tests/compiler/core/algorithms/pedersen64_commit_to_group.leo index b94363498d..e676302ebf 100644 --- a/tests/tests/compiler/core/algorithms/pedersen64_commit_to_group.leo +++ b/tests/tests/compiler/core/algorithms/pedersen64_commit_to_group.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen64_hash_to_address.leo b/tests/tests/compiler/core/algorithms/pedersen64_hash_to_address.leo index 853515f0c8..7917b31748 100644 --- a/tests/tests/compiler/core/algorithms/pedersen64_hash_to_address.leo +++ b/tests/tests/compiler/core/algorithms/pedersen64_hash_to_address.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen64_hash_to_field.leo b/tests/tests/compiler/core/algorithms/pedersen64_hash_to_field.leo index 1b4105943d..973ea07d84 100644 --- a/tests/tests/compiler/core/algorithms/pedersen64_hash_to_field.leo +++ b/tests/tests/compiler/core/algorithms/pedersen64_hash_to_field.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen64_hash_to_group.leo b/tests/tests/compiler/core/algorithms/pedersen64_hash_to_group.leo index b63625fe75..85e42863d5 100644 --- a/tests/tests/compiler/core/algorithms/pedersen64_hash_to_group.leo +++ b/tests/tests/compiler/core/algorithms/pedersen64_hash_to_group.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/core/algorithms/pedersen64_hash_to_scalar.leo b/tests/tests/compiler/core/algorithms/pedersen64_hash_to_scalar.leo index 71777c292e..601f2c506d 100644 --- a/tests/tests/compiler/core/algorithms/pedersen64_hash_to_scalar.leo +++ b/tests/tests/compiler/core/algorithms/pedersen64_hash_to_scalar.leo @@ -1,6 +1,6 @@ /* namespace = "Compile" -expectation = "Pass" +expectation = "Fail" */ program test.aleo { diff --git a/tests/tests/compiler/futures/async_before_call_fail.leo b/tests/tests/compiler/futures/async_before_call_fail.leo new file mode 100644 index 0000000000..e437122bb6 --- /dev/null +++ b/tests/tests/compiler/futures/async_before_call_fail.leo @@ -0,0 +1,22 @@ +/* +namespace = "Compile" +expectation = "Fail" +*/ + +program child.aleo { + transition t() {} +} + + // --- Next Program --- // + +import child.aleo; + +program parent.aleo { + async transition foo() -> Future { + let future: Future = finalize_foo(); + child.aleo/t(); + return future; + } + + async function finalize_foo() {} +} diff --git a/tests/tests/compiler/operations/abs_type_fail.leo b/tests/tests/compiler/operations/abs_type_fail.leo new file mode 100644 index 0000000000..5e7b544c57 --- /dev/null +++ b/tests/tests/compiler/operations/abs_type_fail.leo @@ -0,0 +1,10 @@ +/* +namespace = "Compile" +expectation = "Fail" +*/ + +program test.aleo { + transition main() -> u8 { + return (true ? 1u16.abs() : 2u16.abs()) as u8; + } +} diff --git a/tests/tests/compiler/operations/add_type_fail.leo b/tests/tests/compiler/operations/add_type_fail.leo new file mode 100644 index 0000000000..8a0c918c45 --- /dev/null +++ b/tests/tests/compiler/operations/add_type_fail.leo @@ -0,0 +1,10 @@ +/* +namespace = "Compile" +expectation = "Fail" +*/ + +program test.aleo { + transition main() -> u8 { + return (true + false) as u8; + } +} diff --git a/tests/tests/compiler/records/duplicate_circuit_name_fail.leo b/tests/tests/compiler/records/duplicate_circuit_name_fail.leo index 509fd38e40..530cd6c0f7 100644 --- a/tests/tests/compiler/records/duplicate_circuit_name_fail.leo +++ b/tests/tests/compiler/records/duplicate_circuit_name_fail.leo @@ -3,18 +3,18 @@ namespace = "Compile" expectation = "Fail" */ -program test.aleo { +program test.aleo { record Token { // The token owner. owner: address, // The token amount. amount: u64, } - + struct Token { // This struct cannot have the same name as the record defined above it. x: u32, } - + function main(zz: bool) -> bool { return true; }} diff --git a/tests/tests/compiler/records/same_name_diff_type_fail.leo b/tests/tests/compiler/records/same_name_diff_type_fail.leo new file mode 100644 index 0000000000..892d903da0 --- /dev/null +++ b/tests/tests/compiler/records/same_name_diff_type_fail.leo @@ -0,0 +1,37 @@ +/* +namespace = "Compile" +expectation = "Fail" +*/ + +program child.aleo { + record R { + owner: address, + x: u8, + } + + transition create() -> R { + return R { + owner: self.caller, + x: 1u8, + }; + } +} + +// --- Next Program --- // + +import child.aleo; +program parent.aleo { + record R { + owner: address, + x: u16, + } + + transition check() -> bool { + let r1: R = R { + owner: self.caller, + x: 1u16, + }; + + return r1 == child.aleo/create(); + } +} diff --git a/tests/tests/compiler/ternary/ternary_mismatch_fail.leo b/tests/tests/compiler/ternary/ternary_mismatch_fail.leo new file mode 100644 index 0000000000..0d7cb0fca3 --- /dev/null +++ b/tests/tests/compiler/ternary/ternary_mismatch_fail.leo @@ -0,0 +1,10 @@ +/* +namespace = "Compile" +expectation = "Fail" +*/ + +program test.aleo { + transition main() -> u32 { + return (true ? 1u8 : 1u16) as u32; + } +}