fix wrong variable usage

Separated from #5813.