R. Yehoshua brei d'Rav Idi came to Rav Asi's house. They prepared for him an Eglah Tilsa (a choice calf).
R. Yehoshua: I am fasting today.
Rav Asi's household: Rav Yehudah taught that one may borrow (eat on a day he intended to fast) and repay later!
R. Yehoshua: I am fasting due to a dream;
(Rabah bar Machsiya): A fast helps for (annulling a decree that caused) an (ominous) dream like fire helps for (consuming) stubble.
(Rav Chisda): The fast must be the same day as the dream.
(Rav Yosef): One fasts even on Shabbos.
Question: How should he correct the sin of fasting on Shabbos?
Answer: He should fast another day (during the week).
Berachos 31b (R. Elazar): If one fasts on Shabbos (he suffers greatly, seeing everyone else eating), decrees against him are torn up, even a decree of 70 years (from his youth)!
Nevertheless, he is liable to be punished for not enjoying Shabbos.
(Rav Nachman bar Yitzchak): To atone for this he should fast another day.
Berachos 55b: When Shmuel would have a bad dream, he would say, "va'Chalamos ha'Shav Yedaberu (dreams speak falsely)";
When he would have a good dream, he would recite this verse as a (rhetorical) question -- do dreams speak falsely?! "Ba'Chalam Adaber Bo!"
The Rif (Ta'anis 4a and Shabbos 4b) and Rosh (1:16) bring these Gemaros.
The Rif (Shabbos 5a) and Rosh (Berachos 5:10, citing R. Chananel) say that the Gemara in Berachos discusses a Ta'anis Chalom on Shabbos. Otherwise, one may not fast on Shabbos.
Hagahos Ashri (Ta'anis 1:16) and Shiltei ha'Giborim (Ta'anis 4a:3): Avi ha'Ezri says that the fast to compensate for fasting on Shabbos need not be on Sunday. However, the custom is to fast on Sunday, and one should not deviate. He cites R. Klonimus to say that nowadays we do not have Ta'anis Chalom on Shabbos, for we are not proficient to interpret dreams to know if it is good or bad, like they were in the days of Chachamim; Avi ha'Ezri agreed. This is like Rav Amram; we do not fast when in doubt (if it was a bad dream).
Shiltei ha'Giborim (Shabbos 5a:1): Most Poskim say that we have Ta'anis Chalom on Shabbos nowadays. Rav Hai Gaon says that we fast on Shabbos only for three dreams - seeing a Sefer Torah burned, the rafters of one's house falling, or Yom Kipur at Ne'ilah.
Rambam (Hilchos Ta'anis 1:12): One who has a bad dream must fast the next day in order that he investigate his deeds and repent. He fasts even on Shabbos. He says 'Aneinu' in every Tefilah, even though he did not accept the fast the previous day. One who fasts on Shabbos fasts another day to compensate for Bitul of Oneg Shabbos.
Magid Mishnah: The Rambam learns from Ta'anis and Berachos. He holds like R. Chananel, who says that the only Ta'anis permitted on Shabbos is Ta'anis Chalom.
Lechem Mishneh: What forced the Magid Mishnah to say that the Rambam holds like R. Chananel? Perhaps he learns from Ta'anis! Rather, from Ta'anis there is no source to say that one must fast. We learn this from R. Chananel. Presumably, Ta'anis Chalom is permitted on Shabbos only because it is obligatory.
Shulchan Aruch (OC 220:2): A fast helps to annul a dream like fire helps for stubble.
Kaf ha'Chayim (15): The Rashba says that it is not obligatory to fast, for when Shmuel had a bad dream he would say "va'Chalamos ha'Shav Yedaberu" (and ignore it). One who is not afraid may rely on this to redeem it with money if he is weak, or if it is on Shabbos.
Mishnah Berurah (6): The Ta'anis is like a Korban. It does not help without Teshuvah - "Zevach Resha'im To'evah"
Mishnah Berurah (5): We do not tell a pregnant or nursing woman to fast, rather, to redeem the fast with money.
Rema: The fast must be the same day, even on Shabbos.
Shulchan Aruch (288:4): One may fast a Ta'anis Chalom on Shabbos in order that the decree against him will be torn up.
Beis Yosef (220 Sof DH v'Zeh): The Rosh concludes that he says Aneinu in Elokei Netzor without a Chasimah.
Mishnah Berurah (7): He should spend the entire day learning and praying. He may say Viduy like one who fasts on a weekday. If one had a bad dream similar to what he thought about during the day he does not fast on Shabbos, for his thoughts caused the dream. It is not a message from Shomayim.
Kaf ha'Chayim (16): If he had thoughts on one day and dreamed on a different day, he fasts. If one dreams about Yom Kipur shortly before Yom Kipur, this is because he was thinking about it during the day.
Shulchan Aruch (ibid.): He must fast on Sunday to atone for Bitul of Oneg Shabbos. If he is weak and he cannot fast two consecutive days, he fasts a different day in place of Sunday.
Gra (DH b'Yom): We do not delay something to shield from punishment. This is why Bava ben Buta used to bring Asham Taluy every day (Kerisus 25a).
Mishnah Berurah (8): Some say that if Sunday is an obligatory Ta'anis, no other compensation is needed. Others require that he must fast another day. One may rely on the first opinion is fasting is difficult for him.
Kaf ha'Chayim (27): One who had a bad dream on a Ta'anis Tzibur need not fast an additional day.
Mishnah Berurah (9): One must compensate for a fast on any day on which it is forbidden to fast (not just a custom), e.g. Rosh Chodesh or Chanukah.
Rema: All the more so if Sunday is Chanukah, Rosh Chodesh, Purim, or Yom Tov, even Yom Tov Sheni of Chutz la'Aretz, he postpones the compensatory fast. Some say that if one slept in the afternoon and had a bad dream, he should fast until midnight and make Havdalah. He should fast on Sunday (to compensate) as if he fasted all of Shabbos.
Mishnah Berurah (13): Some say that it suffices to fast until night. One may rely on this if Motza'ei Shabbos is Yom Tov. If one awoke from a bad dream early in the night some say that he fast begins immediately. Others say that it begins in the morning.
Mishnah Berurah (14): Even if he already ate Seudah Shelishis and did not need to eat again, since he refrained l'Shem Ta'anis, it is an Aveirah.
Gra (DH Yesh): We allow completing a fast from Erev Shabbos into Shabbos. Otherwise, one may not deliberately fast on Shabbos for any time.
Kaf ha'Chayim (40): On a weekday one does not fast for a dream during the day.
Shulchan Aruch (5): Some say that one fasts Ta'anis Chalom on Shabbos only if he saw the dream three times. Some say that nowadays one should not fast Ta'anis Chalom on Shabbos, for we are not proficient to interpret dreams to know if it is good or bad. Everyone cites early Seforim to say that we fast on Shabbos for three dreams: one who sees a Sefer Torah burned, Yom Kipur at Ne'ilah, or the rafters of his house or his teeth falling. Some add, if he marries a woman. It seems that one also fasts for the bad dreams mentioned in Perek 9 of Berachos.
Beis Yosef (DH veha'Olam): Some say that we fast also for seeing one read in a Sefer Torah or any part of Yom Kipur.
Magen Avraham (7): The SHLaH says that even for these dreams one fasts only if it is Oneg for him, i.e. he is grieved and he finds solace through fasting. The SHLaH suggests that he accept to fast two days during the week. The Bach says that one who is grieved fasts for any dream; one fasts for the dreams listed even if he is not grieved. I am lenient not to fast, for the Rashba forbids fasting on Shabbos mid'Oraisa. The Rivash says that if one is not concerned for a bad dream, or if the fast upsets him more than the dream, he should not fast. Even during the week it is not a Mitzvah. Magid Mesharim says that to fast only for the three.
Kaf ha'Chayim (15): Poskim argue about whether or not he must fast. Therefore, on Shabbos one should fast only for the three, and only if he is concerned for it.
Mishnah Berurah (6): Here, the Magen Avraham says that Shimon should not fast on Shabbos due to a dream that Reuven saw about him. This implies that during the week, Shimon should fast. Above (220:2) the Magen Avraham connotes that Reuven should fast! Perhaps that is when Reuven does not want to tell Shimon.
Kaf ha'Chayim (13,18): The Tur says that it is Oneg for him to fast, for he is eager to annul the decree. This applies even if he is grieved due to another's dream about him. However, many disagree, so for Kavod Shabbos, one should not fast. Therefore, Reuven should not tell Shimon about the dream.
Magen Avraham (10): Sefer Chasidim says that we do not fast for a dream of monetary loss, only for things for which one may Mechalel Shabbos.
Kaf ha'Chayim (19): This implies that one may fast for monetary loss on a weekday.
Shulchan Aruch (568:2): One cannot 'borrow' a Ta'anis Chalom (eat that day and fast a different day).
Bi'ur Halachah (DH Yachol): The Rema says that if one who is fasting is in great pain he can redeem it by giving Tzedakah. This does not apply to a Ta'anis Chalom.