Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/ast/analyze/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,9 @@ impl CallName {
parse::CallName::TypeCast(target) => {
scope.resolve(target).map(Self::TypeCast).with_span(from)
}
parse::CallName::Custom(name) => {
scope.get_function(name).map(Self::Custom).with_span(from)
}
parse::CallName::Custom(name) => Ok(Self::Custom(scope.get_function(name, from)?)),
parse::CallName::ArrayFold(name, size) => {
let function = scope.get_function(name).with_span(from)?;
let function = scope.get_function(name, from)?;
// A function that is used in a array fold has the signature:
// fn f(element: E, accumulator: A) -> A
if function.params().len() != 2
Expand All @@ -361,7 +359,7 @@ impl CallName {
}
}
parse::CallName::Fold(name, bound) => {
let function = scope.get_function(name).with_span(from)?;
let function = scope.get_function(name, from)?;
// A function that is used in a list fold has the signature:
// fn f(element: E, accumulator: A) -> A
if function.params().len() != 2
Expand All @@ -373,7 +371,7 @@ impl CallName {
}
}
parse::CallName::ForWhile(name) => {
let function = scope.get_function(name).with_span(from)?;
let function = scope.get_function(name, from)?;
// A function that is used in a for-while loop has the signature:
// fn f(accumulator: A, readonly_context: C, counter: u{N}) -> Either<B, A>
// where
Expand Down
2 changes: 1 addition & 1 deletion src/ast/analyze/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod span_tests {

Function::analyze(&parsed, &ResolvedType::unit(), &mut scope).expect("function analyzes");
let function = scope
.get_function(parsed.name())
.get_function(parsed.name(), &parsed)
.expect("function is registered in scope");

assert_eq!(function.span().to_slice(source), Some(source));
Expand Down
2 changes: 1 addition & 1 deletion src/ast/analyze/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl AbstractSyntaxTree for Item {
Function::analyze(function, ty, scope).map(Self::Function)
}
parse::Item::Use(use_decl) => {
scope.resolve_use(use_decl).with_span(use_decl)?;
scope.resolve_use(use_decl);
Ok(Self::Use)
}
parse::Item::EnumDeclaration(decl) => {
Expand Down
20 changes: 16 additions & 4 deletions src/ast/scope/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,12 @@ impl Scope {
self.modules.path()
}

pub(super) fn resolve_use(&mut self, use_decl: &UseDecl) -> Result<(), Error> {
self.modules.resolve_use(use_decl)
pub(super) fn resolve_use(&mut self, use_decl: &UseDecl) {
let span = Span::from(use_decl);

for error in self.modules.resolve_use(use_decl) {
self.report(error.with_span(span));
}
}

pub(super) fn get_alias(&self, name: &AliasName) -> Result<ResolvedType, Error> {
Expand Down Expand Up @@ -288,8 +292,16 @@ impl Scope {
self.modules.insert_function(name, visibility, function)
}

pub(super) fn get_function(&self, name: &FunctionName) -> Result<CustomFunction, Error> {
self.modules.get_function(name)
pub(super) fn get_function(
&self,
name: &FunctionName,
span: impl Into<Span>,
) -> Result<CustomFunction, Failure> {
match self.modules.get_function(name) {
Ok(function) => Ok(function),
Err(_) if self.modules.is_poisoned(name.as_str()) => Err(Failure::Reported),
Err(error) => Err(error.with_span(span.into()).into()),
}
}

/// Insert a variable into the current block.
Expand Down
Loading
Loading