Skip to content

Commit 7da1b76

Browse files
committed
Ensure line and column are included in empty blocks, closes #14931
1 parent f52f395 commit 7da1b76

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ Nonassoc 330 dot_identifier.
9898

9999
%%% MAIN FLOW OF EXPRESSIONS
100100

101-
grammar -> eoe : {'__block__', meta_from_token('$1'), []}.
101+
grammar -> eoe : {'__block__', meta_from_location({1, 1, nil}), []}.
102102
grammar -> expr_list : build_block(reverse('$1')).
103103
grammar -> eoe expr_list : build_block(reverse('$2')).
104104
grammar -> expr_list eoe : build_block(reverse(annotate_eoe('$2', '$1'))).
105105
grammar -> eoe expr_list eoe : build_block(reverse(annotate_eoe('$3', '$2'))).
106-
grammar -> '$empty' : {'__block__', [], []}.
106+
grammar -> '$empty' : {'__block__', meta_from_location({1, 1, nil}), []}.
107107

108108
% Note expressions are on reverse order
109109
expr_list -> expr : ['$1'].

lib/elixir/test/elixir/kernel/parser_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ Code.require_file("../test_helper.exs", __DIR__)
66
defmodule Kernel.ParserTest do
77
use ExUnit.Case, async: true
88

9+
test "empty" do
10+
assert Code.string_to_quoted!("") == {:__block__, [line: 1], []}
11+
assert Code.string_to_quoted!("", columns: true) == {:__block__, [line: 1, column: 1], []}
12+
13+
assert Code.string_to_quoted!(" \n") == {:__block__, [line: 1], []}
14+
assert Code.string_to_quoted!(" \n", columns: true) == {:__block__, [line: 1, column: 1], []}
15+
end
16+
917
describe "nullary ops" do
1018
test "in expressions" do
1119
assert parse!("..") == {:.., [line: 1], []}

0 commit comments

Comments
 (0)