Skip to content

Commit 31068a7

Browse files
committed
fix: await type check diag && better error tolerate
1 parent b3d5f76 commit 31068a7

File tree

6 files changed

+41
-5
lines changed

6 files changed

+41
-5
lines changed

src/ast/node/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl Node for FuncCallNode {
329329
ctx.save_if_comment_doc_hover(id_range, Some(fnvalue.doc.clone()));
330330
handle_ret(ret, rettp, fnvalue.is_declare && skip == 0, ctx, builder)
331331
});
332-
ctx.set_if_refs_tp(pltype, id_range);
332+
// ctx.set_if_refs_tp(pltype, id_range);
333333
ctx.emit_comment_highlight(&self.comments[0]);
334334
res
335335
}

src/ast/node/operator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ impl Node for UnaryOpNode {
8888
.map(|(_, v)| v.clone())
8989
.unwrap_or(Arc::new(RefCell::new(PLType::Unknown)))
9090
}
91-
_ => Arc::new(RefCell::new(PLType::Unknown)),
91+
_ => {
92+
return Err(self
93+
.range
94+
.new_err(ErrorCode::ONLY_TASK_CAN_BE_AWAIT)
95+
.add_label(exp_range, ctx.get_file(), None)
96+
.add_to_ctx(ctx));
97+
}
9298
};
9399
let awaited = builder.await_task(ctx, rv.get_value());
94100
return Ok(NodeOutput::new_value(NodeValue::new(awaited, poll_ty)));

src/nomparser/error.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ where
7777
alt((parser, except(ex, msg, code)))
7878
}
7979

80+
pub fn eat_any_err_block_before<'a, E, F, R>(
81+
parser: F,
82+
parser2: F,
83+
until: &'static str,
84+
code: ErrorCode,
85+
msg: &'static str,
86+
) -> impl FnMut(Span<'a>) -> IResult<Span<'a>, R, E>
87+
where
88+
E: ParseError<Span<'a>> + FromExternalError<Span<'a>, std::fmt::Error>,
89+
F: FnMut(Span<'a>) -> IResult<Span<'a>, R, E>,
90+
{
91+
alt((
92+
parser,
93+
preceded(match_paired_until(until, code, msg), parser2),
94+
))
95+
}
96+
8097
/// match all token with paired `(` or `{` or `[` until find given token out of the paired token
8198
///
8299
/// will report an error

src/nomparser/implement.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::ast::{node::implement::ImplNode, tokens::TokenType};
2+
use error::eat_any_err_block_before;
23
use nom::{
34
combinator::{map_res, opt},
45
multi::many0,
@@ -70,9 +71,21 @@ pub fn impl_def(input: Span) -> IResult<Span, Box<TopLevel>> {
7071
opt(pair(type_name, tag_token_word(TokenType::FOR))),
7172
type_name,
7273
del_newline_or_space!(tag_token_symbol(TokenType::LBRACE)),
73-
many0(del_newline_or_space!(function_def)),
74+
many0(eat_any_err_block_before(
75+
function_def,
76+
function_def,
77+
"\n",
78+
crate::ast::diag::ErrorCode::SYNTAX_ERROR_TOP_STATEMENT,
79+
"failed to parse",
80+
)),
7481
many0(comment),
75-
del_newline_or_space!(tag_token_symbol(TokenType::RBRACE)),
82+
eat_any_err_block_before(
83+
del_newline_or_space!(tag_token_symbol(TokenType::RBRACE)),
84+
del_newline_or_space!(tag_token_symbol(TokenType::RBRACE)),
85+
"}",
86+
crate::ast::diag::ErrorCode::SYNTAX_ERROR_TOP_STATEMENT,
87+
"failed to parse",
88+
),
7689
)),
7790
|(_, generics, impl_trait, structure, (_, start), func_def, comment0, (_, end))| {
7891
res_box(Box::new(TopLevel::ImplDef(ImplNode {

test/main.pi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ async fn main() Task<()> {
7777
println!("async 1");
7878
await delay::delay(2000 as u64);
7979
println!("async 1 end");
80+
8081
await std_test::test_nested_async_closure();
8182
await std_test::test_nested_async_closure_in_normal_f();
8283
await std_test::test_nested_async_closure_in_normal_f2();

test/test/std_test.pi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ impl Task<i64> for CustomTask {
3333
}
3434
return 100 as Option<i64>;
3535
}
36-
3736
}
3837

3938

0 commit comments

Comments
 (0)