40:5מ׳:ה׳
1 א

ויחלמו חלום שניהם. וַיַּחַלְמוּ שְׁנֵיהֶם חֲלוֹם, זֶהוּ פְשׁוּטוֹ, וּמִדְרָשׁוֹ כָּל א' חָלַם חֲלוֹם שְׁנֵיהֶם – שֶׁחָלַם אֶת חֲלוֹמוֹ וּפִתְרוֹן חֲבֵרוֹ, וְזֶהוּ שֶׁנֶּאֱמַר וַיַּרְא שַׂר הָאֹפִים כִּי טוֹב פָּתָר:

ויחלמו חלום שניהם means AND BOTH OF THEM DREAMED A DREAM — This is the real meaning (that שניהם is the subject of ויחלמו and is not to be connected with חלום). A Midrashic explanation is, taking חלום as construct case: each dreamed the dream of both of them — i.e. he dreamed his own dream and the interpretation of the other’s dream. This is what it means when it states (v. 16) “And the chief baker saw that he had interpreted well”). (Genesis Rabbah 88:4; Berakhot 55a).

2 ב

איש כפתרון חלומו. כָּל אֶחָד חָלַם חֲלוֹם הַדּוֹמֶה לְפִתְרוֹן הֶעָתִיד לָבֹא עֲלֵיהֶם:

איש כפתרון חלמו EACH MAN ACCORDING TO THE INTERPRETATION OF HIS DREAM — each dreamed a dream consistent with the interpretation which foretold the future that was to befall them.