This looks like a bug: even if the functions are declared multiple times (in a loop), they are all in the same context (same closure), and should resolve as one, because even their upvalues will be necessarily the same; here the only thing that changes is the current value of the outer variable j=1,2, whose value if not even used in the function and not even part of its closure (if j was part of the closure and used like "
function(x) return 2*x+j end " the value of j would be kept in that closure in upvalues even after the foor loop exits and the local vairavle j no longer exists: that variable would remain in the closure, and in that case the closure should be duplicated creating two separate functions).
For me, as there's a single closure instance, the test should return true in Lua 5.4, like in Lua 5.2 and 5.3; returning to the bad Lua 5.1 behavior is a regression, it just means that we can no longer unify function declarations that are explicitly created in the same closure and not depending on other external variables.