Build fix

fixes #7502
Fix scoping rules for apply rules

fixes #7503