mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-27 12:17:35 +03:00
remove Copy trait from Type enum
This commit is contained in:
parent
00b90c4a33
commit
43db782ce2
@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
/// Explicit type used for defining a variable or expression type
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum Type {
|
||||
// Data types
|
||||
/// The `address` type.
|
||||
|
@ -36,7 +36,7 @@ impl SymbolTable {
|
||||
pub(crate) fn new_function_symbol(id: usize, func: &Function) -> FunctionSymbol {
|
||||
FunctionSymbol {
|
||||
id,
|
||||
output: func.output,
|
||||
output: func.output.clone(),
|
||||
span: func.span,
|
||||
input: func.input.clone(),
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
|
||||
// Lookup circuit variable name.
|
||||
if let Some(actual) = input.members.iter().find(|member| member.identifier.name == name.name) {
|
||||
if let Some(expr) = &actual.expression {
|
||||
self.visit_expression(expr, &Some(*ty));
|
||||
self.visit_expression(expr, &Some(ty.clone()));
|
||||
}
|
||||
} else {
|
||||
self.handler.emit_err(
|
||||
@ -147,7 +147,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
|
||||
if let Some(circuit) = self.symbol_table.borrow().lookup_circuit(&var.name) {
|
||||
Some(self.assert_and_return_type(Type::Identifier(circuit.identifier), expected, var.span))
|
||||
} else if let Some(var) = self.symbol_table.borrow().lookup_variable(&var.name) {
|
||||
Some(self.assert_and_return_type(var.type_, expected, var.span))
|
||||
Some(self.assert_and_return_type(var.type_.clone(), expected, var.span))
|
||||
} else {
|
||||
self.handler
|
||||
.emit_err(TypeCheckerError::unknown_sym("variable", var.name, var.span()).into());
|
||||
@ -366,7 +366,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
|
||||
// Lhs type is checked to be an integer by above.
|
||||
// Rhs type must be magnitude (u8, u16, u32).
|
||||
self.assert_magnitude_type(&t2, input.right.span());
|
||||
*destination
|
||||
destination.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -554,7 +554,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
|
||||
.iter()
|
||||
.zip(input.arguments.iter())
|
||||
.for_each(|(expected, argument)| {
|
||||
self.visit_expression(argument, &Some(expected.get_variable().type_));
|
||||
self.visit_expression(argument, &Some(expected.get_variable().type_.clone()));
|
||||
});
|
||||
|
||||
Some(ret)
|
||||
|
@ -35,13 +35,13 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
|
||||
self.parent = Some(input.name());
|
||||
input.input.iter().for_each(|i| {
|
||||
let input_var = i.get_variable();
|
||||
self.check_ident_type(&Some(input_var.type_));
|
||||
self.check_ident_type(&Some(input_var.type_.clone()));
|
||||
|
||||
// Check for conflicting variable names.
|
||||
if let Err(err) = self.symbol_table.borrow_mut().insert_variable(
|
||||
input_var.identifier.name,
|
||||
VariableSymbol {
|
||||
type_: input_var.type_,
|
||||
type_: input_var.type_.clone(),
|
||||
span: input_var.identifier.span(),
|
||||
declaration: Declaration::Input(input_var.mode()),
|
||||
},
|
||||
|
@ -27,7 +27,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
|
||||
// statements should always have some parent block
|
||||
let parent = self.parent.unwrap();
|
||||
|
||||
let return_type = &self.symbol_table.borrow().lookup_fn(&parent).map(|f| f.output);
|
||||
let return_type = &self.symbol_table.borrow().lookup_fn(&parent).map(|f| f.output.clone());
|
||||
self.check_ident_type(return_type);
|
||||
self.has_return = true;
|
||||
|
||||
@ -42,14 +42,14 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
|
||||
};
|
||||
|
||||
input.variable_names.iter().for_each(|v| {
|
||||
self.check_ident_type(&Some(input.type_));
|
||||
self.check_ident_type(&Some(input.type_.clone()));
|
||||
|
||||
self.visit_expression(&input.value, &Some(input.type_));
|
||||
self.visit_expression(&input.value, &Some(input.type_.clone()));
|
||||
|
||||
if let Err(err) = self.symbol_table.borrow_mut().insert_variable(
|
||||
v.identifier.name,
|
||||
VariableSymbol {
|
||||
type_: input.type_,
|
||||
type_: input.type_.clone(),
|
||||
span: input.span(),
|
||||
declaration: declaration.clone(),
|
||||
},
|
||||
@ -81,7 +81,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Some(var.type_)
|
||||
Some(var.type_.clone())
|
||||
} else {
|
||||
self.handler
|
||||
.emit_err(TypeCheckerError::unknown_sym("variable", var_name.name, var_name.span).into());
|
||||
@ -104,13 +104,13 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
|
||||
}
|
||||
|
||||
fn visit_iteration(&mut self, input: &'a IterationStatement) {
|
||||
let iter_type = &Some(input.type_);
|
||||
let iter_type = &Some(input.type_.clone());
|
||||
self.check_ident_type(iter_type);
|
||||
|
||||
if let Err(err) = self.symbol_table.borrow_mut().insert_variable(
|
||||
input.variable.name,
|
||||
VariableSymbol {
|
||||
type_: input.type_,
|
||||
type_: input.type_.clone(),
|
||||
span: input.span(),
|
||||
declaration: Declaration::Const,
|
||||
},
|
||||
|
@ -105,7 +105,7 @@ impl<'a> TypeChecker<'a> {
|
||||
pub(crate) fn assert_and_return_type(&self, actual: Type, expected: &Option<Type>, span: Span) -> Type {
|
||||
if let Some(expected) = expected {
|
||||
if !actual.eq_flat(expected) {
|
||||
self.emit_err(TypeCheckerError::type_should_be(actual, expected, span));
|
||||
self.emit_err(TypeCheckerError::type_should_be(actual.clone(), expected, span));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user