mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
add symbol creation helper
This commit is contained in:
parent
9f938b9610
commit
40e57142c4
2 changed files with 41 additions and 24 deletions
|
@ -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<Symbol, Type> {
|
||||
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) {
|
||||
let symbol = match make_apply_symbol(env, region, scope, module_name, ident) {
|
||||
Err(problem) => return problem,
|
||||
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 mut args = Vec::new();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue