AI struggles with inferring types in polymorphic code and when duck typing is heavily used. In these scenarios, objects of different types can be treated similarly if they implement a common interface, making it difficult for AI to determine the precise type without runtime context.