Skip to content

Commit

Permalink
ssr: properly match Pat::Literal
Browse files Browse the repository at this point in the history
Summary: As title

Reviewed By: TD5

Differential Revision: D69455464

fbshipit-source-id: f424da4b57d1822464e6eee8421e2d1e444901e5
  • Loading branch information
alanz authored and facebook-github-bot committed Feb 11, 2025
1 parent 863d44a commit eaac6b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/ide_ssr/src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,22 @@ impl<'a> Matcher<'a> {
);
}
}
(
SubIdRef::AnyExprRef(AnyExprRef::Pat(Pat::Literal(pat_lit))),
SubIdRef::AnyExprRef(AnyExprRef::Pat(Pat::Literal(code_lit))),
) => {
let pat_lit_str = render_str(self.sema, pat_lit);
let code_lit_str = render_str(self.sema, code_lit);
if pat_lit_str == code_lit_str {
return Ok(());
} else {
fail_match!(
"Pattern had `{}`, code had `{}`",
&pat_lit_str,
&code_lit_str
);
}
}
(
SubIdRef::AnyExprRef(AnyExprRef::Expr(Expr::Var(code_var))),
SubIdRef::AnyExprRef(AnyExprRef::Expr(Expr::Var(pat_var))),
Expand Down
10 changes: 10 additions & 0 deletions crates/ide_ssr/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,16 @@ fn ssr_expr_case() {
);
}

#[test]
fn ssr_underscore_pattern_in_code_and_placeholder_in_ssr_do_not_match_if_atom_literal_pattens_do_no_match()
{
assert_matches(
"ssr: case X of false -> _@BranchA; _@PatA -> _@BranchB end.",
"foo(X) -> case X of true -> a; _ -> b end.",
&[],
);
}

#[test]
fn ssr_expr_receive() {
assert_matches(
Expand Down

0 comments on commit eaac6b5

Please sign in to comment.