Skip to content

Commit

Permalink
Impl error for unresolved call chains
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejonah1200 committed Sep 10, 2023
1 parent 02c3df9 commit 04098dd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn main() {
let struct_color = colors.next();
rep.with_message(format!(
"No field `{}` found for struct ({}) {}",
rodeo.resolve(&name).fg(struct_color),
rodeo.resolve(&name).fg(ariadne::Color::Red),
project_name.fg(struct_color),
struct_path.fg(struct_color),
))
Expand All @@ -214,7 +214,7 @@ fn main() {
})
.with_label(
ariadne::Label::new((&input_name as &str, name_span.into_range()))
.with_color(colors.next())
.with_color(ariadne::Color::Red)
.with_message("Cannot find this field"),
)
}
Expand Down
42 changes: 25 additions & 17 deletions src/resolution/type_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,26 +865,34 @@ impl<'a> ResolutionEnv<'a> {
let fir::Expression::CallChain { calls, .. } = &chain else {
unreachable!("BUG: resolve_call_chain should return a CallChain");
};
let Infoed {
if let Some(Infoed {
inner: last_kind,
info: last_ty,
span: last_span,
} = calls
.last()
.unwrap_or_else(|| todo!("BUG: should have a least one element in the chain: happens when chain not fully resolved!"));
(
*last_ty,
match last_kind {
fir::CallKind::StructField(dep, struct_id, field_id) => {
AssignableTarget::StructField(*last_ty, *dep, *struct_id, *field_id)
}
fir::CallKind::Variable(var_type) => {
AssignableTarget::Var(*last_ty, var_type.to_owned())
}
_ => todo!("last_kind: _"),
},
*last_span,
)
}) = calls.last()
{
(
*last_ty,
match last_kind {
fir::CallKind::StructField(dep, struct_id, field_id) => {
AssignableTarget::StructField(*last_ty, *dep, *struct_id, *field_id)
}
fir::CallKind::Variable(var_type) => {
AssignableTarget::Var(*last_ty, var_type.to_owned())
}
_ => AssignableTarget::Unnassignable,
},
*last_span,
)
} else {
(try_to_be.unwrap_or_else(|| {
self.resolver.register_type(Type::Error(
self.func_info.file_id,
*call_span,
"unresolved call chain",
))
}), AssignableTarget::Unnassignable, *call_span)
}
}
ast::expressions::Expression::Call(CallKind::Identifier(Spanned(name, var_span))) => {
if let Some((ty, var_ty)) = self.find_var(*name) {
Expand Down
4 changes: 3 additions & 1 deletion tests/test-projects/001/src/main.aplang
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ fn main() {
var d = if (1u16) 1u16 else 1u8
var a = c + (d = r"") - 2u16 / 2u16
println(r"Hello World!")
val person = Person(r"Amejonah", 42u8)
val person = Person(r"Amejonah", 42u8, Address(r"a", 12u16))
test_person(person)
val test = person.a
if(1u16) while(1u16) {}
while(1u16) {}
test_wrong_return(r"6es6") = 0u16
b.a.b = test_wrong_return(16u16)
e = person.address.b
}

0 comments on commit 04098dd

Please sign in to comment.