mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-07 21:15:03 +00:00
fix: the block is assumed to be used in expressions (#1668)
This commit is contained in:
parent
84c211c7eb
commit
b56ba42984
5 changed files with 36 additions and 0 deletions
|
@ -416,6 +416,10 @@ impl LateFuncLinter<'_, '_> {
|
|||
where
|
||||
F: FnOnce(&mut Self) -> Option<()>,
|
||||
{
|
||||
let ctx = match ctx {
|
||||
ExprContext::Block if self.expr_context != ExprContext::Block => ExprContext::BlockExpr,
|
||||
a => a,
|
||||
};
|
||||
let old = std::mem::replace(&mut self.expr_context, ctx);
|
||||
f(self);
|
||||
self.expr_context = old;
|
||||
|
@ -565,6 +569,7 @@ impl DataFlowVisitor for LateFuncLinter<'_, '_> {
|
|||
fn value(&mut self, expr: ast::Expr) -> Option<()> {
|
||||
match self.expr_context {
|
||||
ExprContext::Block => {}
|
||||
ExprContext::BlockExpr => return None,
|
||||
ExprContext::Expr => return None,
|
||||
}
|
||||
|
||||
|
@ -1001,7 +1006,9 @@ impl BuggyBlockLoc<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum ExprContext {
|
||||
BlockExpr,
|
||||
Block,
|
||||
Expr,
|
||||
}
|
||||
|
|
10
crates/tinymist-query/src/fixtures/lint/return_loop3.typ
Normal file
10
crates/tinymist-query/src/fixtures/lint/return_loop3.typ
Normal file
|
@ -0,0 +1,10 @@
|
|||
#let mul-mat(..matrices) = {
|
||||
matrices = matrices.pos()
|
||||
let out = matrices.remove(0)
|
||||
for matrix in matrices {
|
||||
out = for i in range(m) {
|
||||
(i,)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#let get-op(offset, op) = {
|
||||
if op == none {
|
||||
op = if offset < 0 { "<=" } else { ">=" }
|
||||
}
|
||||
|
||||
return op
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/analysis.rs
|
||||
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
|
||||
input_file: crates/tinymist-query/src/fixtures/lint/return_loop3.typ
|
||||
---
|
||||
{}
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/analysis.rs
|
||||
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
|
||||
input_file: crates/tinymist-query/src/fixtures/lint/return_partial_if.typ
|
||||
---
|
||||
{}
|
Loading…
Add table
Add a link
Reference in a new issue