mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 23:23:50 +03:00
fix resolver errors wip 2
This commit is contained in:
parent
323992696c
commit
8f34904fdc
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1285,6 +1285,7 @@ dependencies = [
|
||||
"leo-static-check",
|
||||
"leo-typed",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
|
@ -25,6 +25,9 @@ version = "1.0.3"
|
||||
path = "../imports"
|
||||
version = "1.0.3"
|
||||
|
||||
[dependencies.serde_json]
|
||||
version = "1.0"
|
||||
|
||||
[dependencies.leo-static-check]
|
||||
path = "../static-check"
|
||||
version = "1.0.3"
|
||||
|
@ -41,33 +41,33 @@ impl LeoResolvedAst {
|
||||
let _imported_programs = ImportParser::parse(&program)?;
|
||||
|
||||
// TODO (collinc97): Get input and state file typed syntax tree representations.
|
||||
|
||||
// Create a new symbol table to track of program variables, circuits, and functions by name.
|
||||
let mut symbol_table = SymbolTable::new(None);
|
||||
|
||||
// Pass 1: Check for circuit and function name collisions.
|
||||
symbol_table.pass_one(&program).map_err(|mut e| {
|
||||
// Set the filepath for the error stacktrace.
|
||||
e.set_path(path.clone());
|
||||
|
||||
e
|
||||
})?;
|
||||
|
||||
// Pass 2: Check circuit and function definitions for unknown types.
|
||||
symbol_table.pass_two(&program).map_err(|mut e| {
|
||||
// Set the filepath for the error stacktrace.
|
||||
e.set_path(path.clone());
|
||||
|
||||
e
|
||||
})?;
|
||||
|
||||
// Pass 3: Check statements for type errors.
|
||||
let resolved_ast = Program::resolve(&mut symbol_table, program).map_err(|mut e| {
|
||||
// Set the filepath for the error stacktrace.
|
||||
e.set_path(path);
|
||||
|
||||
e
|
||||
})?;
|
||||
//
|
||||
// // Create a new symbol table to track of program variables, circuits, and functions by name.
|
||||
// let mut symbol_table = SymbolTable::new(None);
|
||||
//
|
||||
// // Pass 1: Check for circuit and function name collisions.
|
||||
// symbol_table.pass_one(&program).map_err(|mut e| {
|
||||
// // Set the filepath for the error stacktrace.
|
||||
// e.set_path(path.clone());
|
||||
//
|
||||
// e
|
||||
// })?;
|
||||
//
|
||||
// // Pass 2: Check circuit and function definitions for unknown types.
|
||||
// symbol_table.pass_two(&program).map_err(|mut e| {
|
||||
// // Set the filepath for the error stacktrace.
|
||||
// e.set_path(path.clone());
|
||||
//
|
||||
// e
|
||||
// })?;
|
||||
//
|
||||
// // Pass 3: Check statements for type errors.
|
||||
// let resolved_ast = Program::resolve(&mut symbol_table, program).map_err(|mut e| {
|
||||
// // Set the filepath for the error stacktrace.
|
||||
// e.set_path(path);
|
||||
//
|
||||
// e
|
||||
// })?;
|
||||
|
||||
Ok(Self { resolved_ast })
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ impl ResolvedNode for Circuit {
|
||||
type_: Type::Circuit(identifier.clone()),
|
||||
attributes: vec![Attribute::Mutable],
|
||||
};
|
||||
child_table.insert_variable(self_key, self_variable);
|
||||
child_table.insert_name(self_key, self_variable);
|
||||
|
||||
// Insert circuit functions into symbol table
|
||||
for function in type_.functions.iter() {
|
||||
|
@ -124,7 +124,7 @@ impl ResolvedNode for Expression {
|
||||
UnresolvedExpression::FunctionCall(function, inputs, span) => {
|
||||
Self::function_call(table, expected_type, function, inputs, span)
|
||||
}
|
||||
UnresolvedExpression::CoreFunctionCall(_name, _inputs, _output, _span) => {
|
||||
UnresolvedExpression::CoreFunctionCall(_name, _inputs, _span) => {
|
||||
unimplemented!("core function calls not type checked")
|
||||
// Self::core_function_call(table, expected_type, function, inputs, span)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{check_tuple_type, Expression, ExpressionValue, ResolvedNode, Statement, StatementError};
|
||||
use leo_static_check::{Attribute, SymbolTable, Type, VariableType};
|
||||
use leo_static_check::{Attribute, ParameterType, SymbolTable, Type};
|
||||
use leo_typed::{Declare, Expression as UnresolvedExpression, Span, VariableName, Variables};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -167,7 +167,7 @@ fn insert_defined_variable(
|
||||
|
||||
// Insert variable into symbol table
|
||||
let key = variable.identifier.name.clone();
|
||||
let value = VariableType {
|
||||
let value = ParameterType {
|
||||
identifier: variable.identifier.clone(),
|
||||
type_: type_.clone(),
|
||||
attributes,
|
||||
@ -200,7 +200,7 @@ impl Statement {
|
||||
|
||||
// If an explicit type is given check that it is valid
|
||||
let expected_type = match &variables.type_ {
|
||||
Some(type_) => Some(Type::resolve(table, (type_.clone(), span.clone()))?),
|
||||
Some(type_) => Some(Type::new(table, type_.clone(), span.clone())?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
@ -222,7 +222,7 @@ impl FunctionBody {
|
||||
/// Returns a new type variable from a given identifier
|
||||
///
|
||||
fn parse_implicit(name: &String) -> Type {
|
||||
Type::TypeVariable(TypeVariable::from(identifier.name.clone()))
|
||||
Type::TypeVariable(TypeVariable::from(name.clone()))
|
||||
}
|
||||
|
||||
///
|
||||
@ -293,7 +293,7 @@ impl FunctionBody {
|
||||
let _condition_type = self.parse_boolean_expression(condition);
|
||||
|
||||
// Check that the types of the first and second expression are equal.
|
||||
self.parse_binary_expression(first, second, span)
|
||||
self.parse_binary_expression(first, second, _span)
|
||||
}
|
||||
|
||||
///
|
||||
@ -403,7 +403,7 @@ impl TypeAssertion {
|
||||
match (&self.left, &self.right) {
|
||||
(Type::TypeVariable(variable), type_) => Some((variable.clone(), type_.clone())),
|
||||
(type_, Type::TypeVariable(variable)) => Some((variable.clone(), type_.clone())),
|
||||
(_type, _type) => None, // No (type variable, type) pair can be returned from two types
|
||||
(_type1, _type2) => None, // No (type variable, type) pair can be returned from two types
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,18 +89,18 @@ impl SymbolTable {
|
||||
self.functions.insert(identifier.name, function_type)
|
||||
}
|
||||
|
||||
// ///
|
||||
// /// Returns a reference to the variable type corresponding to the name.
|
||||
// ///
|
||||
// /// If the symbol table did not have this name present, then `None` is returned.
|
||||
// ///
|
||||
// pub fn get_variable(&self, name: &String) -> Option<&ParameterType> {
|
||||
// // Lookup variable name in symbol table.
|
||||
// match self.names.get(name) {
|
||||
// Some(variable) => Some(variable),
|
||||
// None => None,
|
||||
// }
|
||||
// }
|
||||
///
|
||||
/// Returns a reference to the variable type corresponding to the name.
|
||||
///
|
||||
/// If the symbol table did not have this name present, then `None` is returned.
|
||||
///
|
||||
pub fn get_variable(&self, name: &String) -> Option<&ParameterType> {
|
||||
// Lookup variable name in symbol table.
|
||||
match self.names.get(name) {
|
||||
Some(variable) => Some(variable),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns a reference to the circuit type corresponding to the name.
|
||||
|
@ -20,7 +20,7 @@ use leo_ast::common::VariableName as AstVariableName;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct VariableName {
|
||||
pub mutable: bool,
|
||||
pub identifier: Identifier,
|
||||
|
Loading…
Reference in New Issue
Block a user