There is an argument between R Shimon ben Yochai and the Sages if one can marry a woman who is a idolater but not from the seven Canaanite nations [Emori, Hiti, etc.] [Yebamot 36b]
To the sages this is allowed since the actual verse forbids specifically the seven nations. [And in fact that is how the Tur decided the halacha which is against the Rambam ] R. Shimon says this is not allowed since you go by the reason for the verse.
[That verse says more or less "Do not marry a woman from them (the context refers to the seven Canaanite nations) because they might tilt your heart"]
The well known question here is clear. The law like the sages.
Rav Shach answers based on a Gemara in Sanhedrin. In an argument there on page 21a the sages say a king can not marry more than eighteen wives [לא ירבה לו נשים] R Yehuda says he can have more as long as they do not turn his heart, i.e. he goes only by the reason. R. Shimon says you go by both the literal meaning and also the reason. so even one that turns his heart he can not marry. and more than 18 even like Abigail wife of king David. So what Rav Shach is saying is the Rambam in fact goes by the first sage [Tana Kama] not like R. Yehuda nor R. Shimon. and when the Gemara says the sages of R. Shimon can marry a gentile is meaning R. Yehuda. he would allow this because he goes the reason alone. Rav Shach is saying the verse itself he says is in fact talking about the seven nations but we do not care about that and rather go only by the reason which expands it to all gentiles. THAT IS he is saying the Rambam understands that Gemara in Yevamot differently that we usually understand it.
I have to admit I am having trouble understanding Rav Shach. I definitely need to spend a lot more time on that section. For to R Shimon we go by the reason for the verse and so we forbid marrying all nations that worship idols [Akum]. And R Yehuda goes by the reason for the verse [when the reason is written into the verse] and so he forbids only the seven nations. So I have to admit I am confused here. I assume there must be a way of answering for Rav Shach but it does not occur to me this minute.
[Just information for the general public. Idol worshipers means people that worship idols, not all gentiles. But because of the censors it is hard to know what the original Gemara was saying.
[Later note: In a later blog entry I answered this. The basic idea is that the argument in Yevamot is not between R. Shimon and the sages that always go by the literal meaning, but R. Shimon and R Yehuda who goes only by the spirit of the verse when both are written. R Shimon goes by both when both are written. So back to our case:
To R Shimon only the 7 nations are forbidden because of the spirit of the verse. To R Yehuda all nations are forbidden since the seven nations are not in fact mentioned openly in that specific verse.