Thread error message information for requires

This commit is contained in:
Ayaz Hafiz 2022-05-05 16:52:58 -04:00 committed by Richard Feldman
parent c7142da116
commit 77a1f644a4
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
3 changed files with 22 additions and 14 deletions

View file

@ -50,7 +50,7 @@ pub struct ModuleOutput {
pub problems: Vec<Problem>,
pub referenced_values: VecSet<Symbol>,
pub referenced_types: VecSet<Symbol>,
pub symbols_from_requires: Vec<(Symbol, Loc<Type>)>,
pub symbols_from_requires: Vec<(Loc<Symbol>, Loc<Type>)>,
pub scope: Scope,
}
@ -168,7 +168,7 @@ pub fn canonicalize_module_defs<'a>(
aliases: MutMap<Symbol, Alias>,
exposed_imports: MutMap<Ident, (Symbol, Region)>,
exposed_symbols: &VecSet<Symbol>,
symbols_from_requires: &[(Symbol, Loc<TypeAnnotation<'a>>)],
symbols_from_requires: &[(Loc<Symbol>, Loc<TypeAnnotation<'a>>)],
var_store: &mut VarStore,
) -> Result<ModuleOutput, RuntimeError> {
let mut can_exposed_imports = MutMap::default();

View file

@ -3,13 +3,14 @@ use roc_can::abilities::AbilitiesStore;
use roc_can::constraint::{Constraint, Constraints};
use roc_can::def::Declaration;
use roc_can::expected::Expected;
use roc_can::pattern::Pattern;
use roc_collections::all::MutMap;
use roc_error_macros::internal_error;
use roc_module::symbol::{ModuleId, Symbol};
use roc_region::all::{Loc, Region};
use roc_types::solved_types::{FreeVars, SolvedType};
use roc_types::subs::{VarStore, Variable};
use roc_types::types::{Category, Type};
use roc_types::types::{AnnotationSource, Category, Type};
use crate::expr::{constrain_def_make_constraint, constrain_def_pattern, Env};
@ -96,7 +97,7 @@ pub enum ExposedModuleTypes {
pub fn constrain_module(
constraints: &mut Constraints,
symbols_from_requires: Vec<(Symbol, Loc<Type>)>,
symbols_from_requires: Vec<(Loc<Symbol>, Loc<Type>)>,
abilities_store: &AbilitiesStore,
declarations: &[Declaration],
home: ModuleId,
@ -114,14 +115,14 @@ pub fn constrain_module(
fn constrain_symbols_from_requires(
constraints: &mut Constraints,
symbols_from_requires: Vec<(Symbol, Loc<Type>)>,
symbols_from_requires: Vec<(Loc<Symbol>, Loc<Type>)>,
home: ModuleId,
constraint: Constraint,
) -> Constraint {
symbols_from_requires
.into_iter()
.fold(constraint, |constraint, (symbol, loc_type)| {
if symbol.module_id() == home {
.fold(constraint, |constraint, (loc_symbol, loc_type)| {
if loc_symbol.value.module_id() == home {
// 1. Required symbols can only be specified in package modules
// 2. Required symbols come from app modules
// But, if we are running e.g. `roc check` on a package module, there is no app
@ -130,7 +131,7 @@ fn constrain_symbols_from_requires(
// the types they are annotated with.
let rigids = Default::default();
let env = Env { home, rigids };
let pattern = Loc::at_zero(roc_can::pattern::Pattern::Identifier(symbol));
let pattern = Loc::at_zero(roc_can::pattern::Pattern::Identifier(loc_symbol.value));
let def_pattern_state =
constrain_def_pattern(constraints, &env, &pattern, loc_type.value.clone());
@ -148,10 +149,17 @@ fn constrain_symbols_from_requires(
} else {
// Otherwise, this symbol comes from an app module - we want to check that the type
// provided by the app is in fact what the package module requires.
let arity = loc_type.value.arity();
let provided_eq_requires_constr = constraints.lookup(
symbol,
// TODO give it a real expectation, so errors can be helpful
Expected::NoExpectation(loc_type.value),
loc_symbol.value,
Expected::FromAnnotation(
loc_symbol.map(|&s| Pattern::Identifier(s)),
arity,
AnnotationSource::TypedBody {
region: loc_type.region,
},
loc_type.value,
),
loc_type.region,
);
constraints.and_constraint([provided_eq_requires_constr, constraint])

View file

@ -513,7 +513,7 @@ struct ModuleHeader<'a> {
exposed_imports: MutMap<Ident, (Symbol, Region)>,
parse_state: roc_parse::state::State<'a>,
header_for: HeaderFor<'a>,
symbols_from_requires: Vec<(Symbol, Loc<TypeAnnotation<'a>>)>,
symbols_from_requires: Vec<(Loc<Symbol>, Loc<TypeAnnotation<'a>>)>,
module_timing: ModuleTiming,
}
@ -604,7 +604,7 @@ struct ParsedModule<'a> {
exposed_imports: MutMap<Ident, (Symbol, Region)>,
parsed_defs: &'a [Loc<roc_parse::ast::Def<'a>>],
module_name: ModuleNameEnum<'a>,
symbols_from_requires: Vec<(Symbol, Loc<TypeAnnotation<'a>>)>,
symbols_from_requires: Vec<(Loc<Symbol>, Loc<TypeAnnotation<'a>>)>,
header_for: HeaderFor<'a>,
}
@ -3376,7 +3376,7 @@ fn send_header_two<'a>(
debug_assert!(!scope.contains_key(&ident.clone()));
scope.insert(ident, (symbol, entry.ident.region));
symbols_from_requires.push((symbol, entry.ann));
symbols_from_requires.push((Loc::at(entry.ident.region, symbol), entry.ann));
}
for entry in requires_types {