Skip to content

Commit 73f612f

Browse files
committed
Fix guessed location pointing to tokens on the same line as the block start
1 parent 89b4eb7 commit 73f612f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spec/parser_spec.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,19 @@ thing1()
12381238
thing3()
12391239
end
12401240
until another_thing
1241+
]]))
1242+
end)
1243+
1244+
it("does not report tokens on the same line as the innermost block opening token", function()
1245+
assert.same({line = 6, offset = 78, end_offset = 80, prev_line = 3, prev_offset = 60, prev_end_offset = 61,
1246+
msg = "expected 'end' (to close 'do' on line 3) near less indented 'end' (indentation-based guess)"
1247+
}, get_error([[
1248+
local function f()
1249+
local function g() return ret end
1250+
do
1251+
thing()
1252+
1253+
end
12411254
]]))
12421255
end)
12431256
end)

src/luacheck/parser.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ end
214214
function UnpairedTokenGuesser:check_token()
215215
local top = self.opening_tokens_stack.top
216216

217-
if top and top.eligible then
217+
if top and top.eligible and self.state.line > top.line then
218218
local token_indentation = get_indentation(self.state, self.state.line)
219219

220220
if token_indentation < top.indentation then

0 commit comments

Comments
 (0)