fix use before definition bug from c8f3974a2
(cherry picked from commit fe2c796c41154c6f01bd6095860b819d28b20426)