Avoid segfault if type is not a class
Merge pull request #6260 from wmtan/AvoidSegfault

Avoid segfault if type is not a class