Merge pull request #1601 from rtfeldman/panic-lookup-not-in-scope

Delay panicking on LookupNotInScope until the error is reported
This commit is contained in:
Richard Feldman 2021-08-19 01:36:36 -04:00 committed by GitHub
commit ce9f85ecbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 15 deletions

View file

@ -271,10 +271,20 @@ impl<'a> Context<'a> {
fn get_var_info(&self, symbol: Symbol) -> VarInfo { fn get_var_info(&self, symbol: Symbol) -> VarInfo {
match self.vars.get(&symbol) { match self.vars.get(&symbol) {
Some(info) => *info, Some(info) => *info,
None => panic!( None => {
"Symbol {:?} {} has no info in {:?}", eprintln!(
symbol, symbol, self.vars "Symbol {:?} {} has no info in self.vars",
), symbol,
symbol, // self.vars
);
VarInfo {
persistent: true,
reference: false,
consume: false,
reset: false,
}
}
} }
} }

View file

@ -2682,11 +2682,13 @@ macro_rules! match_on_closure_argument {
let arg_layouts = top_level.arguments; let arg_layouts = top_level.arguments;
let ret_layout = top_level.result; let ret_layout = top_level.result;
match closure_data_layout { match closure_data_layout {
RawFunctionLayout::Function(_, lambda_set, _) => { RawFunctionLayout::Function(_, lambda_set, _) => {
lowlevel_match_on_lambda_set( lowlevel_match_on_lambda_set(
$env, $env,
lambda_set, lambda_set,
$op,
$closure_data_symbol, $closure_data_symbol,
|top_level_function, closure_data, closure_env_layout, specialization_id| self::Call { |top_level_function, closure_data, closure_env_layout, specialization_id| self::Call {
call_type: CallType::HigherOrderLowLevel { call_type: CallType::HigherOrderLowLevel {
@ -7687,6 +7689,7 @@ pub fn num_argument_to_int_or_float(
fn lowlevel_match_on_lambda_set<'a, ToLowLevelCall>( fn lowlevel_match_on_lambda_set<'a, ToLowLevelCall>(
env: &mut Env<'a, '_>, env: &mut Env<'a, '_>,
lambda_set: LambdaSet<'a>, lambda_set: LambdaSet<'a>,
op: LowLevel,
closure_data_symbol: Symbol, closure_data_symbol: Symbol,
to_lowlevel_call: ToLowLevelCall, to_lowlevel_call: ToLowLevelCall,
return_layout: Layout<'a>, return_layout: Layout<'a>,
@ -7726,12 +7729,11 @@ where
env.arena.alloc(result), env.arena.alloc(result),
) )
} }
Layout::Struct(_) => { Layout::Struct(_) => match lambda_set.set.get(0) {
let function_symbol = lambda_set.set[0].0; Some((function_symbol, _)) => {
let call_spec_id = env.next_call_specialization_id(); let call_spec_id = env.next_call_specialization_id();
let call = to_lowlevel_call( let call = to_lowlevel_call(
function_symbol, *function_symbol,
closure_data_symbol, closure_data_symbol,
lambda_set.is_represented(), lambda_set.is_represented(),
call_spec_id, call_spec_id,
@ -7739,6 +7741,17 @@ where
build_call(env, call, assigned, return_layout, env.arena.alloc(hole)) build_call(env, call, assigned, return_layout, env.arena.alloc(hole))
} }
None => {
eprintln!(
"a function passed to `{:?}` LowLevel call has an empty lambda set!
The most likely reason is that some symbol you use is not in scope.
",
op
);
hole.clone()
}
},
Layout::Builtin(Builtin::Int1) => { Layout::Builtin(Builtin::Int1) => {
let closure_tag_id_symbol = closure_data_symbol; let closure_tag_id_symbol = closure_data_symbol;