mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-10 10:02:38 +03:00
Report an error for lookups of unexposed values
This commit is contained in:
parent
7b09232911
commit
572c7cb3dd
@ -200,13 +200,10 @@ pub fn pre_constrain_imports(
|
||||
|
||||
match exposed_types.get(&module_id) {
|
||||
Some(ExposedModuleTypes::Valid(solved_types, new_aliases)) => {
|
||||
let solved_type = solved_types.get(&symbol).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Could not find {:?} in solved_types {:?}",
|
||||
loc_symbol.value, solved_types
|
||||
)
|
||||
});
|
||||
|
||||
// If the exposed value was invalid (e.g. it didn't have
|
||||
// a corresponding definition), it won't have an entry
|
||||
// in solved_types
|
||||
if let Some(solved_type) = solved_types.get(&symbol) {
|
||||
// TODO should this be a union?
|
||||
for (k, v) in new_aliases.clone() {
|
||||
imported_aliases.insert(k, v);
|
||||
@ -217,6 +214,7 @@ pub fn pre_constrain_imports(
|
||||
solved_type: solved_type.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Some(ExposedModuleTypes::Invalid) => {
|
||||
// If that module was invalid, use True constraints
|
||||
// for everything imported from it.
|
||||
|
@ -29,6 +29,22 @@ pub fn type_problem<'b>(
|
||||
CircularType(region, symbol, overall_type) => {
|
||||
to_circular_report(alloc, filename, region, symbol, overall_type)
|
||||
}
|
||||
UnexposedLookup(symbol) => {
|
||||
let title = "UNRECOGNIZED NAME".to_string();
|
||||
let doc = alloc
|
||||
.stack(vec![alloc
|
||||
.reflow("The ")
|
||||
.append(alloc.module(symbol.module_id()))
|
||||
.append(alloc.reflow(" module does not expose anything by the name "))
|
||||
.append(alloc.symbol_unqualified(symbol))])
|
||||
.append(alloc.reflow("."));
|
||||
|
||||
Report {
|
||||
filename,
|
||||
title,
|
||||
doc,
|
||||
}
|
||||
}
|
||||
BadType(type_problem) => {
|
||||
use roc_types::types::Problem::*;
|
||||
match type_problem {
|
||||
|
@ -68,6 +68,7 @@ pub enum TypeError {
|
||||
BadPattern(Region, PatternCategory, ErrorType, PExpected<ErrorType>),
|
||||
CircularType(Region, Symbol, ErrorType),
|
||||
BadType(roc_types::types::Problem),
|
||||
UnexposedLookup(Symbol),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@ -273,15 +274,8 @@ fn solve(
|
||||
}
|
||||
}
|
||||
Lookup(symbol, expectation, region) => {
|
||||
let var = *env.vars_by_symbol.get(&symbol).unwrap_or_else(|| {
|
||||
// TODO Instead of panicking, solve this as True and record
|
||||
// a TypeError ("module Foo does not expose `bar`") for later.
|
||||
panic!(
|
||||
"Could not find symbol {:?} in vars_by_symbol {:?}",
|
||||
symbol, env.vars_by_symbol
|
||||
)
|
||||
});
|
||||
|
||||
match env.vars_by_symbol.get(&symbol) {
|
||||
Some(var) => {
|
||||
// Deep copy the vars associated with this symbol before unifying them.
|
||||
// Otherwise, suppose we have this:
|
||||
//
|
||||
@ -303,7 +297,7 @@ fn solve(
|
||||
// then we copy from that module's Subs into our own. If the value
|
||||
// is being looked up in this module, then we use our Subs as both
|
||||
// the source and destination.
|
||||
let actual = deep_copy_var(subs, rank, pools, var);
|
||||
let actual = deep_copy_var(subs, rank, pools, *var);
|
||||
let expected = type_to_var(
|
||||
subs,
|
||||
rank,
|
||||
@ -341,6 +335,13 @@ fn solve(
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
problems.push(TypeError::UnexposedLookup(*symbol));
|
||||
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
And(sub_constraints) => {
|
||||
let mut state = state;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user