Checking that expr is Expr before matching

Fixes issue #2711