[BZ-996056] fix package cloning when there is a pattern using a class literal referring to a type declaration
(cherry picked from commit cdbc45f88a424816d77dc3adda1c3f4ce1dffada)