mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Thread error message information for requires
This commit is contained in:
parent
c7142da116
commit
77a1f644a4
3 changed files with 22 additions and 14 deletions
|
@ -50,7 +50,7 @@ pub struct ModuleOutput {
|
||||||
pub problems: Vec<Problem>,
|
pub problems: Vec<Problem>,
|
||||||
pub referenced_values: VecSet<Symbol>,
|
pub referenced_values: VecSet<Symbol>,
|
||||||
pub referenced_types: 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,
|
pub scope: Scope,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ pub fn canonicalize_module_defs<'a>(
|
||||||
aliases: MutMap<Symbol, Alias>,
|
aliases: MutMap<Symbol, Alias>,
|
||||||
exposed_imports: MutMap<Ident, (Symbol, Region)>,
|
exposed_imports: MutMap<Ident, (Symbol, Region)>,
|
||||||
exposed_symbols: &VecSet<Symbol>,
|
exposed_symbols: &VecSet<Symbol>,
|
||||||
symbols_from_requires: &[(Symbol, Loc<TypeAnnotation<'a>>)],
|
symbols_from_requires: &[(Loc<Symbol>, Loc<TypeAnnotation<'a>>)],
|
||||||
var_store: &mut VarStore,
|
var_store: &mut VarStore,
|
||||||
) -> Result<ModuleOutput, RuntimeError> {
|
) -> Result<ModuleOutput, RuntimeError> {
|
||||||
let mut can_exposed_imports = MutMap::default();
|
let mut can_exposed_imports = MutMap::default();
|
||||||
|
|
|
@ -3,13 +3,14 @@ use roc_can::abilities::AbilitiesStore;
|
||||||
use roc_can::constraint::{Constraint, Constraints};
|
use roc_can::constraint::{Constraint, Constraints};
|
||||||
use roc_can::def::Declaration;
|
use roc_can::def::Declaration;
|
||||||
use roc_can::expected::Expected;
|
use roc_can::expected::Expected;
|
||||||
|
use roc_can::pattern::Pattern;
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use roc_error_macros::internal_error;
|
use roc_error_macros::internal_error;
|
||||||
use roc_module::symbol::{ModuleId, Symbol};
|
use roc_module::symbol::{ModuleId, Symbol};
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
use roc_types::solved_types::{FreeVars, SolvedType};
|
use roc_types::solved_types::{FreeVars, SolvedType};
|
||||||
use roc_types::subs::{VarStore, Variable};
|
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};
|
use crate::expr::{constrain_def_make_constraint, constrain_def_pattern, Env};
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ pub enum ExposedModuleTypes {
|
||||||
|
|
||||||
pub fn constrain_module(
|
pub fn constrain_module(
|
||||||
constraints: &mut Constraints,
|
constraints: &mut Constraints,
|
||||||
symbols_from_requires: Vec<(Symbol, Loc<Type>)>,
|
symbols_from_requires: Vec<(Loc<Symbol>, Loc<Type>)>,
|
||||||
abilities_store: &AbilitiesStore,
|
abilities_store: &AbilitiesStore,
|
||||||
declarations: &[Declaration],
|
declarations: &[Declaration],
|
||||||
home: ModuleId,
|
home: ModuleId,
|
||||||
|
@ -114,14 +115,14 @@ pub fn constrain_module(
|
||||||
|
|
||||||
fn constrain_symbols_from_requires(
|
fn constrain_symbols_from_requires(
|
||||||
constraints: &mut Constraints,
|
constraints: &mut Constraints,
|
||||||
symbols_from_requires: Vec<(Symbol, Loc<Type>)>,
|
symbols_from_requires: Vec<(Loc<Symbol>, Loc<Type>)>,
|
||||||
home: ModuleId,
|
home: ModuleId,
|
||||||
constraint: Constraint,
|
constraint: Constraint,
|
||||||
) -> Constraint {
|
) -> Constraint {
|
||||||
symbols_from_requires
|
symbols_from_requires
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.fold(constraint, |constraint, (symbol, loc_type)| {
|
.fold(constraint, |constraint, (loc_symbol, loc_type)| {
|
||||||
if symbol.module_id() == home {
|
if loc_symbol.value.module_id() == home {
|
||||||
// 1. Required symbols can only be specified in package modules
|
// 1. Required symbols can only be specified in package modules
|
||||||
// 2. Required symbols come from app 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
|
// 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.
|
// the types they are annotated with.
|
||||||
let rigids = Default::default();
|
let rigids = Default::default();
|
||||||
let env = Env { home, rigids };
|
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 =
|
let def_pattern_state =
|
||||||
constrain_def_pattern(constraints, &env, &pattern, loc_type.value.clone());
|
constrain_def_pattern(constraints, &env, &pattern, loc_type.value.clone());
|
||||||
|
@ -148,10 +149,17 @@ fn constrain_symbols_from_requires(
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, this symbol comes from an app module - we want to check that the type
|
// 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.
|
// 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(
|
let provided_eq_requires_constr = constraints.lookup(
|
||||||
symbol,
|
loc_symbol.value,
|
||||||
// TODO give it a real expectation, so errors can be helpful
|
Expected::FromAnnotation(
|
||||||
Expected::NoExpectation(loc_type.value),
|
loc_symbol.map(|&s| Pattern::Identifier(s)),
|
||||||
|
arity,
|
||||||
|
AnnotationSource::TypedBody {
|
||||||
|
region: loc_type.region,
|
||||||
|
},
|
||||||
|
loc_type.value,
|
||||||
|
),
|
||||||
loc_type.region,
|
loc_type.region,
|
||||||
);
|
);
|
||||||
constraints.and_constraint([provided_eq_requires_constr, constraint])
|
constraints.and_constraint([provided_eq_requires_constr, constraint])
|
||||||
|
|
|
@ -513,7 +513,7 @@ struct ModuleHeader<'a> {
|
||||||
exposed_imports: MutMap<Ident, (Symbol, Region)>,
|
exposed_imports: MutMap<Ident, (Symbol, Region)>,
|
||||||
parse_state: roc_parse::state::State<'a>,
|
parse_state: roc_parse::state::State<'a>,
|
||||||
header_for: HeaderFor<'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,
|
module_timing: ModuleTiming,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,7 +604,7 @@ struct ParsedModule<'a> {
|
||||||
exposed_imports: MutMap<Ident, (Symbol, Region)>,
|
exposed_imports: MutMap<Ident, (Symbol, Region)>,
|
||||||
parsed_defs: &'a [Loc<roc_parse::ast::Def<'a>>],
|
parsed_defs: &'a [Loc<roc_parse::ast::Def<'a>>],
|
||||||
module_name: ModuleNameEnum<'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>,
|
header_for: HeaderFor<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3376,7 +3376,7 @@ fn send_header_two<'a>(
|
||||||
debug_assert!(!scope.contains_key(&ident.clone()));
|
debug_assert!(!scope.contains_key(&ident.clone()));
|
||||||
|
|
||||||
scope.insert(ident, (symbol, entry.ident.region));
|
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 {
|
for entry in requires_types {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue