Refactor dbg expression parsing to work more like function application

Instead of parsing dbg with an expression block, parse the dbg keyword
with no additional arguments. This way the parser treats dbg just like a
variable in function application. We desugar by pattern matching on
`Apply(Dbg, args, called_via)` nodes. This changes the output of syntax
tests since the initial AST is different, but does not change the output
of can or mono.

Add two new errors for dbg in expression position with either no args or
too many args. This is similar to the error behavior of `crash`.

Continue to parse dbg statements with an expression block, as before.
This commit is contained in:
Elias Mulhall 2024-08-29 14:31:35 -04:00
parent 14fabdff07
commit 56c5b790a7
11 changed files with 242 additions and 72 deletions

View file

@ -1207,7 +1207,7 @@ pub fn canonicalize_expr<'a>(
output,
)
}
ast::Expr::Dbg(_) | ast::Expr::DbgStmt(_, _) => {
ast::Expr::Dbg | ast::Expr::DbgStmt(_, _) => {
internal_error!("Dbg should have been desugared by now")
}
ast::Expr::LowLevelDbg((source_location, source), message, continuation) => {
@ -2470,6 +2470,7 @@ pub fn is_valid_interpolation(expr: &ast::Expr<'_>) -> bool {
| ast::Expr::AccessorFunction(_)
| ast::Expr::RecordUpdater(_)
| ast::Expr::Crash
| ast::Expr::Dbg
| ast::Expr::Underscore(_)
| ast::Expr::MalformedIdent(_, _)
| ast::Expr::Tag(_)
@ -2492,7 +2493,6 @@ pub fn is_valid_interpolation(expr: &ast::Expr<'_>) -> bool {
_ => false,
},
// These can contain subexpressions, so we need to recursively check those
ast::Expr::Dbg(expr) => is_valid_interpolation(&expr.value),
ast::Expr::Str(StrLiteral::Line(segments)) => {
segments.iter().all(|segment| match segment {
ast::StrSegment::EscapedChar(_)