Revert "Include annotation type signatures in Expected struct"

This reverts commit 6e4fd5f06a1ae6138659b0073b4e2b375a499588.

This idea didn't work out because cloning the type and storing it on a
variable still resulted in the solver trying to uify the variable with
the type. When there were errors, which there certainly would be if we
tried to unify the variable with a structure that had nested flex/rigid
vars, the nested flex/rigid vars would inherit those errors, and the
program wouldn't typecheck.

Since the motivation here was to expose the signature type to
`reporting` so that we could modify it with suggestions, we should
instead pass that information along in something analogous to the
`Expected` struct.
This commit is contained in:
ayazhafiz 2021-11-25 13:08:18 -05:00
parent a8e38172ac
commit d352d2cdf8
16 changed files with 64 additions and 204 deletions

View file

@ -11,7 +11,7 @@ use roc_types::subs::{
};
use roc_types::types::Type::{self, *};
use roc_types::types::{gather_fields_unsorted_iter, Alias, Category, ErrorType, PatternCategory};
use roc_unify::unify::{unify, unify_without_error_compaction, Unified::*};
use roc_unify::unify::{unify, Unified::*};
use std::collections::hash_map::Entry;
// Type checking system adapted from Elm by Evan Czaplicki, BSD-3-Clause Licensed
@ -66,7 +66,7 @@ use std::collections::hash_map::Entry;
#[derive(PartialEq, Debug, Clone)]
pub enum TypeError {
BadExpr(Region, Category, ErrorType, Expected<ErrorType, ErrorType>),
BadExpr(Region, Category, ErrorType, Expected<ErrorType>),
BadPattern(Region, PatternCategory, ErrorType, PExpected<ErrorType>),
CircularType(Region, Symbol, ErrorType),
BadType(roc_types::types::Problem),
@ -205,9 +205,7 @@ fn solve(
expectation.get_type_ref(),
);
// Don't transform bad types into errors in case we want to grab other types'
// original contents during a failure.
match unify_without_error_compaction(subs, actual, expected) {
match unify(subs, actual, expected) {
Success(vars) => {
introduce(subs, rank, pools, &vars);
@ -220,12 +218,7 @@ fn solve(
*region,
category.clone(),
actual_type,
expectation
.clone()
.replace(expected_type)
.replace_annotation_with(|annot_var: Variable| {
subs.var_to_error_type(annot_var).0
}),
expectation.clone().replace(expected_type),
);
problems.push(problem);
@ -301,9 +294,7 @@ fn solve(
cached_aliases,
expectation.get_type_ref(),
);
// Don't transform bad types into errors in case we want to grab other types'
// original contents during a failure.
match unify_without_error_compaction(subs, actual, expected) {
match unify(subs, actual, expected) {
Success(vars) => {
introduce(subs, rank, pools, &vars);
@ -317,12 +308,7 @@ fn solve(
*region,
Category::Lookup(*symbol),
actual_type,
expectation
.clone()
.replace(expected_type)
.replace_annotation_with(|annot_var: Variable| {
subs.var_to_error_type(annot_var).0
}),
expectation.clone().replace(expected_type),
);
problems.push(problem);