fix: the block is assumed to be used in expressions (#1668)

This commit is contained in:
Myriad-Dreamin 2025-04-16 18:47:08 +08:00 committed by GitHub
parent 84c211c7eb
commit b56ba42984
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 0 deletions

View file

@ -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,
}

View 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
}

View file

@ -0,0 +1,7 @@
#let get-op(offset, op) = {
if op == none {
op = if offset < 0 { "<=" } else { ">=" }
}
return op
}

View file

@ -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
---
{}

View file

@ -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
---
{}