Skip to content

Commit

Permalink
Skipping expansion on any underlying parser errors. (#6415)
Browse files Browse the repository at this point in the history
  • Loading branch information
orizi authored Sep 24, 2024
1 parent f9697a4 commit d6f9822
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
21 changes: 15 additions & 6 deletions crates/cairo-lang-semantic/src/expr/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use cairo_lang_syntax::node::ast::{
use cairo_lang_syntax::node::db::SyntaxGroup;
use cairo_lang_syntax::node::helpers::{GetIdentifier, PathSegmentEx};
use cairo_lang_syntax::node::ids::SyntaxStablePtrId;
use cairo_lang_syntax::node::kind::SyntaxKind;
use cairo_lang_syntax::node::{ast, Terminal, TypedStablePtr, TypedSyntaxNode};
use cairo_lang_utils as utils;
use cairo_lang_utils::ordered_hash_map::{Entry, OrderedHashMap};
Expand Down Expand Up @@ -398,12 +399,20 @@ fn compute_expr_inline_macro_semantic(
};

// Skipping expanding an inline macro if it had a parser error.
if matches!(syntax.arguments(syntax_db), ast::WrappedArgList::Missing(_)) {
return Ok(Expr::Missing(ExprMissing {
ty: TypeId::missing(ctx.db, skip_diagnostic()),
stable_ptr: ast::Expr::InlineMacro(syntax.clone()).stable_ptr(),
diag_added: skip_diagnostic(),
}));
if syntax.as_syntax_node().descendants(syntax_db).any(|node| {
matches!(
node.kind(syntax_db),
SyntaxKind::ExprMissing
| SyntaxKind::WrappedArgListMissing
| SyntaxKind::StatementMissing
| SyntaxKind::ModuleItemMissing
| SyntaxKind::TraitItemMissing
| SyntaxKind::ImplItemMissing
| SyntaxKind::TokenMissing
| SyntaxKind::TokenSkipped
)
}) {
return Err(skip_diagnostic());
}

let result = macro_plugin.generate_code(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,22 @@ error: Plugin diagnostic: Closing `}` without a matching `{`.
--> lib.cairo:2:8
panic!("bad_format(})")
^*************^

//! > ==========================================================================

//! > Test expansion of macro with inner parse errors.

//! > test_runner_name
test_expand_expr(expect_diagnostics: true)

//! > expr_code
array![format!]

//! > expanded_code
array![format!]

//! > diagnostics
error: Missing tokens. Expected an argument list wrapped in either parentheses, brackets, or braces.
--> lib.cairo:2:15
array![format!]
^

0 comments on commit d6f9822

Please sign in to comment.