A cascade reaction with iminium ion isomerization as the key step leading to tetrahydropyrimido[4,5-d]pyrimidines.