Skip to content

Commit

Permalink
fix: report missing trait instance function instead of causing ice!() (
Browse files Browse the repository at this point in the history
…#33)

This was a lazy todo from the unification of methods. This now properly
reports the correct diagnostic code.
  • Loading branch information
junlarsen authored Feb 4, 2025
1 parent 5726473 commit d4d667c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions compiler/eight-middle/src/hir_type_check_pass/typing_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use eight_diagnostics::errors::hir::{
BindingReDeclaresName, ConstructingNonStructTypeError, ConstructingPointerTypeError,
DereferenceOfNonPointerError, FunctionTypeMismatchError, HirError,
InvalidFieldReferenceOfNonStructError, InvalidStructFieldReferenceError, MissingFieldError,
SelfReferentialTypeError, TraitDoesNotExistError, TraitMissingInstanceError, TypeMismatchError,
TypeParameterShadowsExisting, UnknownFieldError, WrongFunctionTypeArgumentCount,
SelfReferentialTypeError, TraitDoesNotExistError, TraitInstanceMissingFnError,
TraitMissingInstanceError, TypeMismatchError, TypeParameterShadowsExisting, UnknownFieldError,
WrongFunctionTypeArgumentCount,
};
use eight_diagnostics::ice;
use eight_span::Span;
Expand Down Expand Up @@ -976,16 +977,13 @@ impl<'hir> TypingContext<'hir> {
trait_substitutions.as_slice(),
)
.unwrap_or_else(|| ice!("trait instance not found"));
let method = instance
.methods
.get(&constraint.method_name)
.unwrap_or_else(|| {
ice!(
"trait instance does not have method {}",
constraint.method_name
)
});

let method = instance.methods.get(&constraint.method_name).ok_or(
HirError::TraitInstanceMissingFn(TraitInstanceMissingFnError {
name: constraint.trait_name.to_owned(),
method: constraint.method_name.to_owned(),
span: constraint.method_name_span,
}),
)?;
// Ensure that the method type parameters are substituted for the provided type arguments.
for (param, arg) in method
.type_parameters
Expand Down
2 changes: 1 addition & 1 deletion compiler/eight-tests/tests/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn test_evaluate_stdlib() {
.is_file()
})
.collect::<Vec<_>>();
files.sort_by(|a, b| a.path().cmp(&b.path()));
files.sort_by_key(|a| a.path());
let mut buf = String::new();
for file in files {
let path = file.path();
Expand Down

0 comments on commit d4d667c

Please sign in to comment.