As a temporary work around I have defeated the compile time constant detection in lparser.c (line 1774), and this problem goes away.
For some reason the OP_CLOSE for the end of the "do .. end" block is not generated if this block is preceded by a couple of compile time constant declarations.
Gé
A bit more digging: the file is not closed at the end of the 'do ... end' block. Tracing the system calls shows that the file is closed after the error message (probably by __gc).
If I look at the generated code it seems like the slot for variable 'file' gets reused by 'database'.
Gé
BTW: platform: 64-bit x86 Debian 10 Linux.
I tested this with an unmodified Lua, built with the distributed Makefile to rule out any mistakes on my part.
Thanks,
Gé
--
--