diff --git a/compiler/ast/src/common/identifier.rs b/compiler/ast/src/common/identifier.rs
index e520d98a47..d3e2c9a64b 100644
--- a/compiler/ast/src/common/identifier.rs
+++ b/compiler/ast/src/common/identifier.rs
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see .
+use leo_errors::Result;
use leo_span::{Span, Symbol};
use crate::Node;
@@ -50,6 +51,10 @@ impl Node for Identifier {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result> {
+ Ok(None)
+ }
}
impl Identifier {
diff --git a/compiler/ast/src/expression/binary.rs b/compiler/ast/src/expression/binary.rs
index 5be8b12901..32aaa0c72a 100644
--- a/compiler/ast/src/expression/binary.rs
+++ b/compiler/ast/src/expression/binary.rs
@@ -156,4 +156,21 @@ impl Node for BinaryExpression {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ match self.op.class() {
+ BinaryOperationClass::Boolean => Ok(Some(Type::Boolean)),
+ BinaryOperationClass::Numeric => {
+ let left = self.left.get_type()?;
+ let right = self.right.get_type()?;
+
+ match (left, right) {
+ (Some(t1), Some(t2)) if t1 == t2 => Ok(Some(t1)),
+ (None, None) => Ok(None),
+ (Some(t1), Some(t2)) => todo!("throw err"),
+ (None, Some(t)) | (Some(t), None) => todo!("throw err"),
+ }
+ }
+ }
+ }
}
diff --git a/compiler/ast/src/expression/call.rs b/compiler/ast/src/expression/call.rs
index 2670141391..6c1c975129 100644
--- a/compiler/ast/src/expression/call.rs
+++ b/compiler/ast/src/expression/call.rs
@@ -49,4 +49,8 @@ impl Node for CallExpression {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(None)
+ }
}
diff --git a/compiler/ast/src/expression/err.rs b/compiler/ast/src/expression/err.rs
index 23c94eeeeb..afa09f12a2 100644
--- a/compiler/ast/src/expression/err.rs
+++ b/compiler/ast/src/expression/err.rs
@@ -37,4 +37,8 @@ impl Node for ErrExpression {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(None)
+ }
}
diff --git a/compiler/ast/src/expression/mod.rs b/compiler/ast/src/expression/mod.rs
index e4f0e7a117..d28403463e 100644
--- a/compiler/ast/src/expression/mod.rs
+++ b/compiler/ast/src/expression/mod.rs
@@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see .
-use crate::{GroupValue, Identifier, IntegerType, Node};
-
+use crate::{GroupValue, Identifier, IntegerType, Node, Type};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -80,6 +80,19 @@ impl Node for Expression {
Err(n) => n.set_span(span),
}
}
+
+ fn get_type(&self) -> Result > {
+ use Expression::*;
+ match self {
+ Identifier(n) => n.get_type(),
+ Value(n) => n.get_type(),
+ Binary(n) => n.get_type(),
+ Unary(n) => n.get_type(),
+ Ternary(n) => n.get_type(),
+ Call(n) => n.get_type(),
+ Err(n) => n.get_type(),
+ }
+ }
}
impl fmt::Display for Expression {
diff --git a/compiler/ast/src/expression/ternary.rs b/compiler/ast/src/expression/ternary.rs
index 55b17a0630..738b0565de 100644
--- a/compiler/ast/src/expression/ternary.rs
+++ b/compiler/ast/src/expression/ternary.rs
@@ -43,4 +43,8 @@ impl Node for TernaryExpression {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(None)
+ }
}
diff --git a/compiler/ast/src/expression/unary.rs b/compiler/ast/src/expression/unary.rs
index 4f52cc0d19..f627f267d6 100644
--- a/compiler/ast/src/expression/unary.rs
+++ b/compiler/ast/src/expression/unary.rs
@@ -64,4 +64,8 @@ impl Node for UnaryExpression {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ self.inner.get_type()
+ }
}
diff --git a/compiler/ast/src/expression/value.rs b/compiler/ast/src/expression/value.rs
index 566abd4321..da22d2d267 100644
--- a/compiler/ast/src/expression/value.rs
+++ b/compiler/ast/src/expression/value.rs
@@ -33,8 +33,6 @@ pub enum ValueExpression {
/// A group literal, either product or affine.
/// For example, `42group` or `(12, 52)group`.
Group(Box),
- /// A negated non-integer literal, e.g., `-4.2`.
- Implicit(String, #[serde(with = "leo_span::span_json")] Span),
/// An integer literal, e.g., `42`.
Integer(IntegerType, String, #[serde(with = "leo_span::span_json")] Span),
/// A string literal, e.g., `"foobar"`.
@@ -49,7 +47,6 @@ impl fmt::Display for ValueExpression {
Boolean(boolean, _) => write!(f, "{}", boolean),
Char(character) => write!(f, "{}", character),
Field(field, _) => write!(f, "{}", field),
- Implicit(implicit, _) => write!(f, "{}", implicit),
Integer(type_, value, _) => write!(f, "{}{}", value, type_),
Group(group) => write!(f, "{}", group),
String(string, _) => {
@@ -66,12 +63,7 @@ impl Node for ValueExpression {
fn span(&self) -> &Span {
use ValueExpression::*;
match &self {
- Address(_, span)
- | Boolean(_, span)
- | Field(_, span)
- | Implicit(_, span)
- | Integer(_, _, span)
- | String(_, span) => span,
+ Address(_, span) | Boolean(_, span) | Field(_, span) | Integer(_, _, span) | String(_, span) => span,
Char(character) => &character.span,
Group(group) => match &**group {
GroupValue::Single(_, span) => span,
@@ -83,12 +75,9 @@ impl Node for ValueExpression {
fn set_span(&mut self, new_span: Span) {
use ValueExpression::*;
match self {
- Address(_, span)
- | Boolean(_, span)
- | Field(_, span)
- | Implicit(_, span)
- | Integer(_, _, span)
- | String(_, span) => *span = new_span,
+ Address(_, span) | Boolean(_, span) | Field(_, span) | Integer(_, _, span) | String(_, span) => {
+ *span = new_span
+ }
Char(character) => character.span = new_span,
Group(group) => match &mut **group {
GroupValue::Single(_, span) => *span = new_span,
@@ -96,4 +85,17 @@ impl Node for ValueExpression {
},
}
}
+
+ fn get_type(&self) -> Result> {
+ use ValueExpression::*;
+ Ok(Some(match &self {
+ Address(_, _) => Type::Address,
+ Boolean(_, _) => Type::Boolean,
+ Char(_) => Type::Char,
+ Field(_, _) => Type::Field,
+ Integer(type_, _, _) => Type::IntegerType(*type_),
+ Group(_) => Type::Group,
+ String(_, _) => return Ok(None),
+ }))
+ }
}
diff --git a/compiler/ast/src/functions/function.rs b/compiler/ast/src/functions/function.rs
index 63128083be..ed8d1c0c8f 100644
--- a/compiler/ast/src/functions/function.rs
+++ b/compiler/ast/src/functions/function.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Block, FunctionInput, Identifier, Node, Type};
+use leo_errors::Result;
use leo_span::{sym, Span, Symbol};
use serde::{Deserialize, Serialize};
@@ -92,4 +93,8 @@ impl Node for Function {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(Some(self.output.clone()))
+ }
}
diff --git a/compiler/ast/src/functions/input/function_input.rs b/compiler/ast/src/functions/input/function_input.rs
index 19494375e5..c2be83f140 100644
--- a/compiler/ast/src/functions/input/function_input.rs
+++ b/compiler/ast/src/functions/input/function_input.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Identifier, Node, Type};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -99,4 +100,8 @@ impl Node for FunctionInputVariable {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(Some(self.type_.clone()))
+ }
}
diff --git a/compiler/ast/src/functions/input/input_variable.rs b/compiler/ast/src/functions/input/input_variable.rs
index 9317cb7b23..3e0aebbedc 100644
--- a/compiler/ast/src/functions/input/input_variable.rs
+++ b/compiler/ast/src/functions/input/input_variable.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{FunctionInputVariable, Node};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -83,4 +84,11 @@ impl Node for FunctionInput {
Variable(variable) => variable.span = span,
}
}
+
+ fn get_type(&self) -> Result > {
+ use FunctionInput::*;
+ match self {
+ Variable(variable) => variable.get_type(),
+ }
+ }
}
diff --git a/compiler/ast/src/input/input_value.rs b/compiler/ast/src/input/input_value.rs
index bb46164825..b5dc1c904a 100644
--- a/compiler/ast/src/input/input_value.rs
+++ b/compiler/ast/src/input/input_value.rs
@@ -42,11 +42,8 @@ impl TryFrom<(Type, Expression)> for InputValue {
Self::Boolean(bool_value)
}
(Type::Char, ValueExpression::Char(value)) => Self::Char(value),
- (Type::Field, ValueExpression::Field(value, _) | ValueExpression::Implicit(value, _)) => {
- Self::Field(value)
- }
+ (Type::Field, ValueExpression::Field(value, _)) => Self::Field(value),
(Type::Group, ValueExpression::Group(value)) => Self::Group(*value),
- (Type::IntegerType(type_), ValueExpression::Implicit(value, _)) => Self::Integer(type_, value),
(Type::IntegerType(expected), ValueExpression::Integer(actual, value, span)) => {
if expected == actual {
Self::Integer(expected, value)
diff --git a/compiler/ast/src/node.rs b/compiler/ast/src/node.rs
index be0c100b9c..7f62efcaed 100644
--- a/compiler/ast/src/node.rs
+++ b/compiler/ast/src/node.rs
@@ -14,8 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see .
+use leo_errors::Result;
use leo_span::Span;
+use crate::Type;
+
/// A node in the AST.
pub trait Node:
std::fmt::Debug + std::fmt::Display + Clone + PartialEq + Eq + serde::Serialize + serde::de::DeserializeOwned
@@ -25,4 +28,7 @@ pub trait Node:
/// Sets the span of the node.
fn set_span(&mut self, span: Span);
+
+ /// Gets the type of the node if it exists.
+ fn get_type(&self) -> Result >;
}
diff --git a/compiler/ast/src/statements/assign/mod.rs b/compiler/ast/src/statements/assign/mod.rs
index fed8398c28..e78e617c1a 100644
--- a/compiler/ast/src/statements/assign/mod.rs
+++ b/compiler/ast/src/statements/assign/mod.rs
@@ -15,7 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Expression, Node};
-
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -109,4 +109,8 @@ impl Node for AssignStatement {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ self.value.get_type()
+ }
}
diff --git a/compiler/ast/src/statements/block.rs b/compiler/ast/src/statements/block.rs
index e54a4a6ba5..62e20c2af2 100644
--- a/compiler/ast/src/statements/block.rs
+++ b/compiler/ast/src/statements/block.rs
@@ -14,7 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see .
-use crate::{Node, Statement};
+use crate::{Node, Statement, Type};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -51,4 +52,8 @@ impl Node for Block {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(None)
+ }
}
diff --git a/compiler/ast/src/statements/conditional.rs b/compiler/ast/src/statements/conditional.rs
index 2e4adf6b65..e9895382f5 100644
--- a/compiler/ast/src/statements/conditional.rs
+++ b/compiler/ast/src/statements/conditional.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Block, Expression, Node, Statement};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -51,4 +52,8 @@ impl Node for ConditionalStatement {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(None)
+ }
}
diff --git a/compiler/ast/src/statements/console/console_args.rs b/compiler/ast/src/statements/console/console_args.rs
index 4c03aa26df..6eb79ae7ae 100644
--- a/compiler/ast/src/statements/console/console_args.rs
+++ b/compiler/ast/src/statements/console/console_args.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Char, Expression, Node};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -54,4 +55,8 @@ impl Node for ConsoleArgs {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(None)
+ }
}
diff --git a/compiler/ast/src/statements/console/console_function.rs b/compiler/ast/src/statements/console/console_function.rs
index dc7a2baf08..e22928e77b 100644
--- a/compiler/ast/src/statements/console/console_function.rs
+++ b/compiler/ast/src/statements/console/console_function.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{ConsoleArgs, Expression, Node};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -58,4 +59,8 @@ impl Node for ConsoleFunction {
ConsoleFunction::Error(formatted) | ConsoleFunction::Log(formatted) => formatted.set_span(span),
}
}
+
+ fn get_type(&self) -> Result > {
+ Ok(None)
+ }
}
diff --git a/compiler/ast/src/statements/console/console_statement.rs b/compiler/ast/src/statements/console/console_statement.rs
index 7673ef3ca3..28fd48fe2a 100644
--- a/compiler/ast/src/statements/console/console_statement.rs
+++ b/compiler/ast/src/statements/console/console_statement.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{ConsoleFunction, Node};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -49,4 +50,8 @@ impl Node for ConsoleStatement {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(None)
+ }
}
diff --git a/compiler/ast/src/statements/definition/mod.rs b/compiler/ast/src/statements/definition/mod.rs
index 4f0e514438..1cdaf2dd76 100644
--- a/compiler/ast/src/statements/definition/mod.rs
+++ b/compiler/ast/src/statements/definition/mod.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Expression, Node, Type};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -72,4 +73,8 @@ impl Node for DefinitionStatement {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(Some(self.type_.clone()))
+ }
}
diff --git a/compiler/ast/src/statements/definition/variable_name.rs b/compiler/ast/src/statements/definition/variable_name.rs
index 71f43aa6d1..22b169c7e6 100644
--- a/compiler/ast/src/statements/definition/variable_name.rs
+++ b/compiler/ast/src/statements/definition/variable_name.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Identifier, Node};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -45,4 +46,8 @@ impl Node for VariableName {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(None)
+ }
}
diff --git a/compiler/ast/src/statements/expression.rs b/compiler/ast/src/statements/expression.rs
index 93ed15c3e5..e429109f1e 100644
--- a/compiler/ast/src/statements/expression.rs
+++ b/compiler/ast/src/statements/expression.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Expression, Node};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -43,4 +44,8 @@ impl Node for ExpressionStatement {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ self.expression.get_type()
+ }
}
diff --git a/compiler/ast/src/statements/iteration.rs b/compiler/ast/src/statements/iteration.rs
index 3fdfc94bc9..00ac0f7830 100644
--- a/compiler/ast/src/statements/iteration.rs
+++ b/compiler/ast/src/statements/iteration.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Block, Expression, Identifier, Node, Type};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -59,4 +60,8 @@ impl Node for IterationStatement {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ Ok(Some(self.type_.clone()))
+ }
}
diff --git a/compiler/ast/src/statements/return_statement.rs b/compiler/ast/src/statements/return_statement.rs
index e1d25dc050..ae9f00a8dd 100644
--- a/compiler/ast/src/statements/return_statement.rs
+++ b/compiler/ast/src/statements/return_statement.rs
@@ -15,6 +15,7 @@
// along with the Leo library. If not, see .
use crate::{Expression, Node};
+use leo_errors::Result;
use leo_span::Span;
use serde::{Deserialize, Serialize};
@@ -43,4 +44,8 @@ impl Node for ReturnStatement {
fn set_span(&mut self, span: Span) {
self.span = span;
}
+
+ fn get_type(&self) -> Result > {
+ self.expression.get_type()
+ }
}
diff --git a/compiler/ast/src/statements/statement.rs b/compiler/ast/src/statements/statement.rs
index c6f97e8f45..c6d6aed9a0 100644
--- a/compiler/ast/src/statements/statement.rs
+++ b/compiler/ast/src/statements/statement.rs
@@ -14,7 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see .
-use crate::{ConditionalStatement, Node};
+use crate::{ConditionalStatement, Node, Type};
+use leo_errors::Result;
use leo_span::Span;
use super::*;
@@ -86,4 +87,18 @@ impl Node for Statement {
Block(n) => n.set_span(span),
}
}
+
+ fn get_type(&self) -> Result > {
+ use Statement::*;
+ match self {
+ Return(n) => n.get_type(),
+ Definition(n) => n.get_type(),
+ Assign(n) => n.get_type(),
+ Conditional(n) => n.get_type(),
+ Iteration(n) => n.get_type(),
+ Console(n) => n.get_type(),
+ Expression(n) => n.get_type(),
+ Block(n) => n.get_type(),
+ }
+ }
}
diff --git a/compiler/parser/src/test.rs b/compiler/parser/src/test.rs
index abe1d50c21..6eb034b686 100644
--- a/compiler/parser/src/test.rs
+++ b/compiler/parser/src/test.rs
@@ -76,10 +76,6 @@ fn with_handler(
Ok(parsed)
}
-fn implicit_value_expr() -> Expression {
- Expression::Value(ValueExpression::Implicit("".into(), Span::default()))
-}
-
fn tokenize(test: Test) -> Result, String> {
tokenizer::tokenize("test", &test.content).map_err(|x| x.to_string())
}
@@ -105,7 +101,7 @@ impl Namespace for ParseExpressionNamespace {
create_session_if_not_set_then(|_| {
let tokenizer = tokenize(test)?;
if all_are_comments(&tokenizer) {
- return Ok(yaml_or_fail(implicit_value_expr()));
+ return Ok(yaml_or_fail(""));
}
with_handler(tokenizer, |p| p.parse_expression()).map(yaml_or_fail)
})
@@ -124,7 +120,7 @@ impl Namespace for ParseStatementNamespace {
let tokenizer = tokenize(test)?;
if all_are_comments(&tokenizer) {
return Ok(yaml_or_fail(Statement::Expression(ExpressionStatement {
- expression: implicit_value_expr(),
+ expression: Expression::Value(ValueExpression::String(Vec::new(), Default::default())),
span: Span::default(),
})));
}
diff --git a/compiler/passes/src/lib.rs b/compiler/passes/src/lib.rs
index efc2b74574..4d56f75550 100644
--- a/compiler/passes/src/lib.rs
+++ b/compiler/passes/src/lib.rs
@@ -31,3 +31,6 @@ pub use self::pass::*;
pub mod symbol_table;
pub use symbol_table::*;
+
+pub mod type_checker;
+pub use type_checker::*;
diff --git a/compiler/passes/src/symbol_table/table.rs b/compiler/passes/src/symbol_table/table.rs
index ccc6a3f363..5425c24af5 100644
--- a/compiler/passes/src/symbol_table/table.rs
+++ b/compiler/passes/src/symbol_table/table.rs
@@ -53,6 +53,10 @@ impl<'a> SymbolTable<'a> {
self.functions.insert(symbol, function);
Ok(())
}
+
+ pub fn lookup_fn(&mut self, symbol: &Symbol) -> Option<&&'a Function> {
+ self.functions.get(symbol)
+ }
}
impl<'a> Display for SymbolTable<'a> {
diff --git a/compiler/passes/src/type_checker/check.rs b/compiler/passes/src/type_checker/check.rs
new file mode 100644
index 0000000000..5d6f78446d
--- /dev/null
+++ b/compiler/passes/src/type_checker/check.rs
@@ -0,0 +1,42 @@
+// Copyright (C) 2019-2022 Aleo Systems Inc.
+// This file is part of the Leo library.
+
+// The Leo library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// The Leo library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with the Leo library. If not, see .
+
+use leo_ast::*;
+
+use crate::TypeChecker;
+
+impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {}
+
+impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
+ fn visit_return(&mut self, input: &'a ReturnStatement) -> VisitResult {
+ let parent = self.parent.unwrap();
+ if let Some(func) = self.symbol_table.lookup_fn(&parent) {
+ // if func.get_type()? != input.get_type()? {
+ // // self.handler.emit_err(err);
+ // }
+ }
+
+ VisitResult::VisitChildren
+ }
+}
+
+impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
+ fn visit_function(&mut self, input: &'a Function) -> VisitResult {
+ self.symbol_table.clear_variables();
+ self.parent = Some(input.name());
+ VisitResult::VisitChildren
+ }
+}
diff --git a/compiler/passes/src/type_checker/checker.rs b/compiler/passes/src/type_checker/checker.rs
new file mode 100644
index 0000000000..da4fb88117
--- /dev/null
+++ b/compiler/passes/src/type_checker/checker.rs
@@ -0,0 +1,36 @@
+// Copyright (C) 2019-2022 Aleo Systems Inc.
+// This file is part of the Leo library.
+
+// The Leo library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// The Leo library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with the Leo library. If not, see .
+
+use leo_errors::emitter::Handler;
+use leo_span::Symbol;
+
+use crate::SymbolTable;
+
+pub struct TypeChecker<'a> {
+ pub(crate) symbol_table: SymbolTable<'a>,
+ pub(crate) handler: &'a Handler,
+ pub(crate) parent: Option,
+}
+
+impl<'a> TypeChecker<'a> {
+ pub fn new(symbol_table: SymbolTable<'a>, handler: &'a Handler) -> Self {
+ Self {
+ symbol_table,
+ handler,
+ parent: None,
+ }
+ }
+}
diff --git a/compiler/passes/src/type_checker/mod.rs b/compiler/passes/src/type_checker/mod.rs
new file mode 100644
index 0000000000..f33bf66bdd
--- /dev/null
+++ b/compiler/passes/src/type_checker/mod.rs
@@ -0,0 +1,39 @@
+// Copyright (C) 2019-2022 Aleo Systems Inc.
+// This file is part of the Leo library.
+
+// The Leo library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// The Leo library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with the Leo library. If not, see .
+
+pub mod check;
+pub use check::*;
+
+pub mod checker;
+pub use checker::*;
+
+use crate::{Pass, SymbolTable};
+
+use leo_ast::{Ast, VisitorDirector};
+use leo_errors::{emitter::Handler, Result};
+
+impl<'a> Pass<'a> for TypeChecker<'a> {
+ type Input = (&'a Ast, SymbolTable<'a>, &'a Handler);
+ type Output = Result<()>;
+
+ fn do_pass((ast, symbol_table, handler): Self::Input) -> Self::Output {
+ let mut visitor = VisitorDirector::new(TypeChecker::new(symbol_table, handler));
+ visitor.visit_program(ast.as_repr());
+ handler.last_err()?;
+
+ Ok(())
+ }
+}
diff --git a/tests/expectations/parser/parser/expression/literal/int_parse/field.leo.out b/tests/expectations/parser/parser/expression/literal/int_parse/field.leo.out
index 9c571beb3d..2b86197922 100644
--- a/tests/expectations/parser/parser/expression/literal/int_parse/field.leo.out
+++ b/tests/expectations/parser/parser/expression/literal/int_parse/field.leo.out
@@ -32,16 +32,7 @@ outputs:
col_stop: 9
path: ""
content: 456field
- - Value:
- Implicit:
- - ""
- - span:
- line_start: 0
- line_stop: 0
- col_start: 0
- col_stop: 0
- path: ""
- content: ""
+ - ""
- Value:
Field:
- "87377802873778028737780287377802873778028737780287377802873778028737780287377802"
diff --git a/tests/expectations/parser/parser/unreachable/postfix_pass.leo.out b/tests/expectations/parser/parser/unreachable/postfix_pass.leo.out
index 47a8e8b1fb..f274e7c5f3 100644
--- a/tests/expectations/parser/parser/unreachable/postfix_pass.leo.out
+++ b/tests/expectations/parser/parser/unreachable/postfix_pass.leo.out
@@ -5,8 +5,8 @@ outputs:
- Expression:
expression:
Value:
- Implicit:
- - ""
+ String:
+ - []
- span:
line_start: 0
line_stop: 0