Fix Trac #1746: make rule-matching work properly with Cast expressions