Add the assertion for instance of.

It would be nice if you coud merge my optimize change.