diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 92f1ef54aa..1dd38fb97b 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -102,6 +102,40 @@ pub fn canonicalize_annotation( } } +fn make_apply_symbol( + env: &mut Env, + region: Region, + scope: &mut Scope, + module_name: &str, + ident: &str, +) -> Result { + if module_name.is_empty() { + // Since module_name was empty, this is an unqualified type. + // Look it up in scope! + let ident: Ident = (*ident).into(); + + match scope.lookup(&ident, region) { + Ok(symbol) => Ok(symbol), + Err(problem) => { + env.problem(roc_problem::can::Problem::RuntimeError(problem)); + + Err(Type::Erroneous(Problem::UnrecognizedIdent(ident))) + } + } + } else { + match env.qualified_lookup(module_name, ident, region) { + Ok(symbol) => Ok(symbol), + Err(problem) => { + // Either the module wasn't imported, or + // it was imported but it doesn't expose this ident. + env.problem(roc_problem::can::Problem::RuntimeError(problem)); + + Err(Type::Erroneous(Problem::UnrecognizedIdent((*ident).into()))) + } + } + } +} + #[allow(clippy::too_many_arguments)] fn can_annotation_help( env: &mut Env, @@ -150,30 +184,9 @@ fn can_annotation_help( Type::Function(args, Box::new(closure), Box::new(ret)) } Apply(module_name, ident, type_arguments) => { - let symbol = if module_name.is_empty() { - // Since module_name was empty, this is an unqualified type. - // Look it up in scope! - let ident: Ident = (*ident).into(); - - match scope.lookup(&ident, region) { - Ok(symbol) => symbol, - Err(problem) => { - env.problem(roc_problem::can::Problem::RuntimeError(problem)); - - return Type::Erroneous(Problem::UnrecognizedIdent(ident)); - } - } - } else { - match env.qualified_lookup(module_name, ident, region) { - Ok(symbol) => symbol, - Err(problem) => { - // Either the module wasn't imported, or - // it was imported but it doesn't expose this ident. - env.problem(roc_problem::can::Problem::RuntimeError(problem)); - - return Type::Erroneous(Problem::UnrecognizedIdent((*ident).into())); - } - } + let symbol = match make_apply_symbol(env, region, scope, module_name, ident) { + Err(problem) => return problem, + Ok(symbol) => symbol, }; let mut args = Vec::new(); diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 0833f0fa11..d9e90efc14 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -179,6 +179,7 @@ pub fn canonicalize_defs<'a>( let mut aliases = SendMap::default(); let mut value_defs = Vec::new(); + println!("anew"); for pending_def in pending.into_iter() { match pending_def { PendingDef::Alias { name, vars, ann } => { @@ -233,6 +234,7 @@ pub fn canonicalize_defs<'a>( ); } + dbg!(symbol); scope.add_alias(symbol, ann.region, can_vars.clone(), can_ann.typ.clone()); let alias = scope.lookup_alias(symbol).expect("alias is added to scope"); aliases.insert(symbol, alias.clone()); @@ -917,6 +919,7 @@ fn canonicalize_pending_def<'a>( } } + dbg!(symbol); scope.add_alias(symbol, name.region, can_vars.clone(), can_ann.typ.clone()); if can_ann.typ.contains_symbol(symbol) { @@ -927,6 +930,7 @@ fn canonicalize_pending_def<'a>( let mut rec_type_union = Type::RecursiveTagUnion(rec_var, tags, ext); rec_type_union.substitute_alias(symbol, &Type::Variable(rec_var)); + dbg!(symbol); scope.add_alias(symbol, name.region, can_vars, rec_type_union); } else { env.problems