rewriter typechecks