symbol_resolver: handle list and tuples
This commit is contained in:
parent
56f082ca7c
commit
c356062239
@ -94,7 +94,8 @@ pub fn parse_type_annotation<T>(
|
||||
},
|
||||
Subscript { value, slice, .. } => {
|
||||
if let Name { id, .. } = &value.node {
|
||||
if id == "virtual" {
|
||||
match id.as_str() {
|
||||
"virtual" => {
|
||||
let ty = parse_type_annotation(
|
||||
resolver,
|
||||
top_level_defs,
|
||||
@ -103,7 +104,37 @@ pub fn parse_type_annotation<T>(
|
||||
slice,
|
||||
)?;
|
||||
Ok(unifier.add_ty(TypeEnum::TVirtual { ty }))
|
||||
}
|
||||
"list" => {
|
||||
let ty = parse_type_annotation(
|
||||
resolver,
|
||||
top_level_defs,
|
||||
unifier,
|
||||
primitives,
|
||||
slice,
|
||||
)?;
|
||||
Ok(unifier.add_ty(TypeEnum::TList { ty }))
|
||||
}
|
||||
"tuple" => {
|
||||
if let Tuple { elts, .. } = &slice.node {
|
||||
let ty = elts
|
||||
.iter()
|
||||
.map(|elt| {
|
||||
parse_type_annotation(
|
||||
resolver,
|
||||
top_level_defs,
|
||||
unifier,
|
||||
primitives,
|
||||
elt,
|
||||
)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(unifier.add_ty(TypeEnum::TTuple { ty }))
|
||||
} else {
|
||||
Err("Expected multiple elements for tuple".into())
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let types = if let Tuple { elts, .. } = &slice.node {
|
||||
elts.iter()
|
||||
.map(|v| {
|
||||
@ -140,7 +171,8 @@ pub fn parse_type_annotation<T>(
|
||||
}
|
||||
let mut subst = HashMap::new();
|
||||
for (var, ty) in izip!(type_vars.iter(), types.iter()) {
|
||||
let id = if let TypeEnum::TVar { id, .. } = &*unifier.get_ty(var.1) {
|
||||
let id = if let TypeEnum::TVar { id, .. } = &*unifier.get_ty(var.1)
|
||||
{
|
||||
*id
|
||||
} else {
|
||||
unreachable!()
|
||||
@ -167,6 +199,7 @@ pub fn parse_type_annotation<T>(
|
||||
Err("Cannot use function name as type".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err("unsupported type expression".into())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user