Report exposed-but-not-defined symbols

This commit is contained in:
Richard Feldman 2020-12-10 23:17:10 -05:00
parent 14288d5aa6
commit ed222912b3
3 changed files with 16 additions and 2 deletions

View File

@ -240,8 +240,8 @@ pub fn canonicalize_module_defs<'a>(
// exposed_symbols and added to exposed_vars_by_symbol. If any were // exposed_symbols and added to exposed_vars_by_symbol. If any were
// not, that means they were declared as exposed but there was // not, that means they were declared as exposed but there was
// no actual declaration with that name! // no actual declaration with that name!
if !exposed_symbols.is_empty() { for symbol in exposed_symbols {
panic!("TODO gracefully handle invalid `exposes` entry (or entries) which had no corresponding definition: {:?}", exposed_symbols); env.problem(Problem::ExposedButNotDefined(symbol));
} }
// Incorporate any remaining output.lookups entries into references. // Incorporate any remaining output.lookups entries into references.

View File

@ -12,6 +12,7 @@ use roc_region::all::{Located, Region};
pub enum Problem { pub enum Problem {
UnusedDef(Symbol, Region), UnusedDef(Symbol, Region),
UnusedImport(ModuleId, Region), UnusedImport(ModuleId, Region),
ExposedButNotDefined(Symbol),
/// First symbol is the name of the closure with that argument /// First symbol is the name of the closure with that argument
/// Second symbol is the name of the argument that is unused /// Second symbol is the name of the argument that is unused
UnusedArgument(Symbol, Symbol, Region), UnusedArgument(Symbol, Symbol, Region),

View File

@ -37,6 +37,19 @@ pub fn can_problem<'b>(
alloc.module(module_id), alloc.module(module_id),
alloc.reflow(" isn't used, you don't need to import it."), alloc.reflow(" isn't used, you don't need to import it."),
]), ]),
Problem::ExposedButNotDefined(symbol) => {
alloc.stack(vec![
alloc
.symbol_unqualified(symbol)
.append(alloc.reflow(" is listed as exposed, but it isn't defined in this module.")),
alloc
.reflow("You can fix this by adding a definition for ")
.append(alloc.symbol_unqualified(symbol))
.append(alloc.reflow(", or by removing it from "))
.append(alloc.keyword("exposes"))
.append(alloc.reflow("."))
])
}
Problem::UnusedArgument(closure_symbol, argument_symbol, region) => { Problem::UnusedArgument(closure_symbol, argument_symbol, region) => {
let line = "\". Adding an underscore at the start of a variable name is a way of saying that the variable is not used."; let line = "\". Adding an underscore at the start of a variable name is a way of saying that the variable is not used.";