Add self dependencies.

Fixes #5157
Fixes #5328