mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-01 21:40:58 +00:00
Only allow indented else if there's a newline after the else
This commit is contained in:
parent
48c941d542
commit
cabe67f88d
5 changed files with 94 additions and 1 deletions
|
|
@ -2762,8 +2762,12 @@ fn if_expr_help<'a>(options: ExprParseOptions) -> impl Parser<'a, Expr<'a>, EIf<
|
|||
}
|
||||
};
|
||||
|
||||
let has_newline_next = require_newline_or_eof(EExpr::IndentEnd)
|
||||
.parse(arena, state_final_else.clone(), min_indent)
|
||||
.is_ok();
|
||||
|
||||
let else_indent = state_final_else.line_indent();
|
||||
let indented_else = else_indent > if_indent;
|
||||
let indented_else = else_indent > if_indent && has_newline_next;
|
||||
|
||||
let min_indent = if !indented_else {
|
||||
else_indent + 1
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
if
|
||||
h
|
||||
then
|
||||
A
|
||||
else
|
||||
&e
|
||||
s #
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
SpaceAfter(
|
||||
Defs(
|
||||
Defs {
|
||||
tags: [
|
||||
EitherIndex(2147483648),
|
||||
],
|
||||
regions: [
|
||||
@0-20,
|
||||
],
|
||||
space_before: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
space_after: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
spaces: [],
|
||||
type_defs: [],
|
||||
value_defs: [
|
||||
Stmt(
|
||||
@0-20 If {
|
||||
if_thens: [
|
||||
(
|
||||
@3-4 SpaceBefore(
|
||||
SpaceAfter(
|
||||
Var {
|
||||
module_name: "",
|
||||
ident: "h",
|
||||
},
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
@10-11 SpaceBefore(
|
||||
SpaceAfter(
|
||||
Tag(
|
||||
"A",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
final_else: @18-20 RecordUpdater(
|
||||
"e",
|
||||
),
|
||||
indented_else: false,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
@21-22 SpaceBefore(
|
||||
Var {
|
||||
module_name: "",
|
||||
ident: "s",
|
||||
},
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
),
|
||||
[
|
||||
LineComment(
|
||||
"",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
if
|
||||
h
|
||||
then
|
||||
A
|
||||
else &e
|
||||
s#
|
||||
|
|
@ -274,6 +274,7 @@ mod test_snapshots {
|
|||
pass/ability_multi_line.expr,
|
||||
pass/ability_single_line.expr,
|
||||
pass/ability_two_in_a_row.expr,
|
||||
pass/accidentally_indented_else.expr,
|
||||
pass/add_var_with_spaces.expr,
|
||||
pass/add_with_spaces.expr,
|
||||
pass/alias_ann_in_parens.expr,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue