Strange problem with type checker at end of if statement