check exact cast before checking transitive ones (closes #2614)