It's correct grammar. But the meaning does not make sense. It means that Mary gave orders to the cake.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.
eipjooA textbook says the example is ungrammatical,Ungrammatical and nonsensical. Mary told John to cut the cake. / John was told by Mary to cut the cake. / Mary had John cut the cake. [ Take your pick. ]