Can you gain fat while losing muscle

So people talking about gaining muscle while losing fat has got me thinking. Usually the thought process surrounds eating more than you need on lifting days and less than you need on rest day. If this is true than suppose you ate less than you need on lifting days and more than you needed on rest days, wouldn't this lead to you losing muscle and gaining fat. No I don't really believe that this would happen I just wanted to put it out here to see what other peoples thoughts are.