erlang/otp — pull request #296 by nox (2014-03-16 14:18:36+00:00)
Title: Rewrite merge of clause variable tables (in case, try, etc)

erl_lint:icrt_export/4 has been rewritten to make the code really follow the scoping rules of Erlang, and not just in most situations by accident.

* The function should not depend on calling unused_vars/3 because that function does not return variables which begins with an underscore, something that only matters when emitting warnings. This could cause a compiler crash if such a variable was reused afterwards.

* The variable tables from each clause are first merged together, lists:merge/1 is safe to use because they are orddicts and thus already sorted. This list is then traversed parallelly to the old variable table, again taking advantage of their sorted order.

* The function does not emit warnings itself, there is no need to pass around the lint state. In the same vein, vtunsafe/3 has been rewritten to do more things by itself, given that all of its calls were similar. Finally, compiled-out code has been removed.

* This reverts the code in 9ce148b1059e4da746a11f1d80a653340216c468, which fixed the compiler crash and made erl_lint remember unsafe variables, but forget about unused variables in the process.

* Other places of the code which relied on the old clunky behaviour were also updated: unused and unsafe old variables are forgotten when merging fun clauses and boolean shortcircuiting operators do not rely on icrt_export/3 anymore.

I had submitted this already in the past but had retracted it with the hope of finding a cleaner fix. I didn't find one.