Skip to content

Commit

Permalink
5/n update HIR for string sigils: type_expr
Browse files Browse the repository at this point in the history
Summary: As title

Reviewed By: robertoaloi

Differential Revision: D57613983

fbshipit-source-id: 8c93443b2abbd401676b4aa837585b62b80f4141
  • Loading branch information
alanz authored and facebook-github-bot committed Jun 27, 2024
1 parent 60f7eb5 commit f3b2402
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/hir/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,14 @@ impl<'a> Ctx<'a> {
self.alloc_type_expr(TypeExpr::Missing, Some(expr))
}
ast::ExprMax::String(str) => {
let value = lower_str(str).map_or(TypeExpr::Missing, TypeExpr::Literal);
let value = self
.lower_str_or_sigil(
str,
expr,
Self::lower_binary_string_literal_type_expr,
TypeExpr::Literal,
)
.unwrap_or(TypeExpr::Missing);
self.alloc_type_expr(value, Some(expr))
}
ast::ExprMax::TryExpr(_try_expr) => self.alloc_type_expr(TypeExpr::Missing, Some(expr)),
Expand Down Expand Up @@ -2576,6 +2583,14 @@ impl<'a> Ctx<'a> {
Some(Pat::Binary { segs })
}

fn lower_binary_string_literal_type_expr(
&mut self,
_string: Literal,
_expr: &ast::Expr,
) -> Option<TypeExpr> {
None
}

fn resolve_name(&mut self, name: ast::Name) -> Option<Atom> {
let expr_id = self.lower_expr(&name.into());
if let Expr::Literal(Literal::Atom(atom)) = self.body[expr_id] {
Expand Down
19 changes: 19 additions & 0 deletions crates/hir/src/body/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,7 @@ fn verbatim_string_with_sigil_in_tq_string() {
// End of verbatim string tests
// -------------------------------------
}

#[test]
// Since we use a generic lowering thoroughly tested for `Expr`, we
// just do an existence test for `Pat`.
Expand All @@ -2444,3 +2445,21 @@ fn verbatim_binary_sigil_in_pat() {
"#]],
);
}

#[test]
// Since we use a generic lowering thoroughly tested for `Expr`, we
// just do an existence test for `TypeExpr`.
fn verbatim_binary_sigil_in_type() {
// Note: \~ gets replaced by ~ in the fixture parsing
check(
r#"
-type foo() :: \~B"ab\"c\"\d").
-type bar() :: "hello").
"#,
expect![[r#"
-type foo() :: [missing].
-type bar() :: "hello".
"#]],
);
}

0 comments on commit f3b2402

Please sign in to comment.