forked from M-Labs/nac3
report unbound identifier errors
This commit is contained in:
parent
befd01b240
commit
10fd4d3c27
13
src/main.rs
13
src/main.rs
@ -23,6 +23,7 @@ enum CompileErrorKind {
|
|||||||
MissingTypeAnnotation,
|
MissingTypeAnnotation,
|
||||||
UnknownTypeAnnotation,
|
UnknownTypeAnnotation,
|
||||||
IncompatibleTypes,
|
IncompatibleTypes,
|
||||||
|
UnboundIdentifier,
|
||||||
Internal(&'static str)
|
Internal(&'static str)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,6 +38,8 @@ impl fmt::Display for CompileErrorKind {
|
|||||||
=> write!(f, "Unknown type annotation"),
|
=> write!(f, "Unknown type annotation"),
|
||||||
CompileErrorKind::IncompatibleTypes
|
CompileErrorKind::IncompatibleTypes
|
||||||
=> write!(f, "Incompatible types"),
|
=> write!(f, "Incompatible types"),
|
||||||
|
CompileErrorKind::UnboundIdentifier
|
||||||
|
=> write!(f, "Unbound identifier"),
|
||||||
CompileErrorKind::Internal(details)
|
CompileErrorKind::Internal(details)
|
||||||
=> write!(f, "Internal compiler error: {}", details),
|
=> write!(f, "Internal compiler error: {}", details),
|
||||||
}
|
}
|
||||||
@ -171,12 +174,14 @@ impl<'ctx> CodeGen<'ctx> {
|
|||||||
) -> CompileResult<values::BasicValueEnum<'ctx>> {
|
) -> CompileResult<values::BasicValueEnum<'ctx>> {
|
||||||
self.set_source_location(expression.location);
|
self.set_source_location(expression.location);
|
||||||
|
|
||||||
use ast::ExpressionType::*;
|
|
||||||
match &expression.node {
|
match &expression.node {
|
||||||
Identifier { name } => {
|
ast::ExpressionType::Identifier { name } => {
|
||||||
Ok(*self.namespace.get(name).unwrap())
|
match self.namespace.get(name) {
|
||||||
|
Some(value) => Ok(*value),
|
||||||
|
None => Err(self.compile_error(CompileErrorKind::UnboundIdentifier))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Binop { a, op, b } => {
|
ast::ExpressionType::Binop { a, op, b } => {
|
||||||
let a = self.compile_expression(&a)?;
|
let a = self.compile_expression(&a)?;
|
||||||
let b = self.compile_expression(&b)?;
|
let b = self.compile_expression(&b)?;
|
||||||
if a.get_type() != b.get_type() {
|
if a.get_type() != b.get_type() {
|
||||||
|
Loading…
Reference in New Issue
Block a user