[AST] Follow-up for r201468, move the check to the caller and add an assertion.

Suggested by Richard Smith.