Fix #6647 (incorrect scope order).
Merge pull request #6653 from busykai/fix-6647

Fix #6647