Skip to content

Commit

Permalink
Actually accumulate results somewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
purefunctor committed Feb 15, 2024
1 parent 8d3de2f commit 99379c0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/analyzer-module/src/infer/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ pub enum Hint {
}

/// The kind of the inference error.
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub enum InferErrorKind {
CannotUnify(CoreTypeId, CoreTypeId),
OccursCheck(InFile<u32>, CoreTypeId),
}

/// An error encountered during inference.
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub struct InferError {
pub hints: Arc<[Hint]>,
pub kind: InferErrorKind,
Expand Down
7 changes: 6 additions & 1 deletion crates/analyzer-module/src/infer/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
id::InFile, infer::pretty_print, scope::ResolveInfo, surface::tree::*, InferenceDatabase,
};

use super::{Constraint, CoreType, CoreTypeId, Hint, InferMap};
use super::{Constraint, CoreType, CoreTypeId, Hint, InferError, InferMap};

use recursive::{recursive_data_groups, recursive_let_names, recursive_value_groups};

Expand All @@ -25,6 +25,7 @@ struct InferState {
count: u32,
hints: Vec<Hint>,
constraints: Vec<Constraint>,
errors: Vec<InferError>,
infer_map: InferMap,
}

Expand Down Expand Up @@ -62,6 +63,10 @@ impl<'a> InferContext<'a> {
fn add_constraint(&mut self, constraint: Constraint) {
self.state.constraints.push(constraint)
}

fn add_error(&mut self, error: InferError) {
self.state.errors.push(error)
}
}

type UnificationDeferred = (Arc<[Hint]>, InFile<u32>, InFile<u32>);
Expand Down
14 changes: 12 additions & 2 deletions crates/analyzer-module/src/infer/rules/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,20 @@ impl InferContext<'_> {
(_, CoreType::Unification(y_u)) => {
self.add_constraint(Constraint::UnifySolve(hints, y_u, x_id));
}
(CoreType::Constructor(x_c), CoreType::Constructor(y_c)) => if x_c != y_c {},
(CoreType::Constructor(x_c), CoreType::Constructor(y_c)) => {
if x_c != y_c {
self.add_error(InferError {
hints,
kind: InferErrorKind::CannotUnify(x_id, y_id),
})
}
}
(CoreType::Primitive(x_p), CoreType::Primitive(y_p)) => {
if x_p != y_p {
dbg!(InferError { hints, kind: InferErrorKind::CannotUnify(x_id, y_id) });
self.add_error(InferError {
hints,
kind: InferErrorKind::CannotUnify(x_id, y_id),
});
}
}
(x_ty, y_ty) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/analyzer-module/src/infer/rules/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'i, 'a> SolveContext<'i, 'a> {
y_t: CoreTypeId,
) {
if occurs_check(db, x_u, y_t) {
dbg!(InferError { hints, kind: InferErrorKind::OccursCheck(x_u, y_t) });
self.infer.add_error(InferError { hints, kind: InferErrorKind::OccursCheck(x_u, y_t) });
return;
}
if let Some(x_t) = self.state.unification_solved.get(&x_u) {
Expand Down

0 comments on commit 99379c0

Please sign in to comment.