Fix name-capture bug in rule matching