I saw Father Adam and Abraham; and my father and my mother; my brother Alvin, that has long since slept; And marveled how it was that he had obtained an inheritance in that kingdom, seeing that he had departed this life before the Lord had set his hand to gather Israel the Second time, and had not been baptized for the remission of sins. Thus came the voice of the Lord unto me, saying: All who have died without a knowledge of this gospel, who would have received it if they had been permitted to tarry, shall be heirs of the celestial kingdom of God; Also all that shall die henceforth without a knowledge of it, who would have received it with all their hearts, shall be heirs of that kingdom; For I, the Lord, will judge all men according to their works, according to the desire of their hearts. (D&C 137:5-9)
There is a debate among many within the broad Christian spectrum as to whether God possesses knowledge of counterfactuals. I am of the belief that he does, based on my understanding of God's foreknowledge (being an Open Theist myself) as well as uniquely Latter-day Saint scriptures, including D&C 137, quoted in part above.
Latter-day Saint philosopher Blake Ostler wrote in defence of this position, with a focus on D&C 137, the following:
This scripture clearly indicates that God saves people based upon what they would have done if they had been allowed to live beyond the time that they do live in mortality. Thus, God must have knowledge of counterfactuals of freedom such as:
(3) If a free agent A were allowed to live in the in the circumstances contained in the actual world beyond the time A would freely accept the gospel with all his/her heart.
This scripture seems to indicate that God can judge persons on the basis of their “hearts” or dispositions established prior to their death. In this particular case, Joseph Smith was surprised to learn that his brother Alvin had been saved in the celestial kingdom even though Alvin had died before the gospel was restored. Joseph learned that God knows whether Alvin would have accepted the gospel is the actual would had been different and if Alvin had been allowed to live until after the gospel had been restored in 1830. In fact, Joseph learned that the following proposition is true.
(4) If Alvin Smith had been allowed to live until the gospel had been restored in 1830, then Alvin would have accepted the gospel with all his heart.
Thus, the Mormon scriptures seem to base God’s providence and judgment, at least in part, on God’s knowledge of counterfactuals of freedom. Mormon scriptures thus seems to be committed to the view that such counterfactuals of freedom have a truth value (i.e., at least one of each such proposition or its negation is true under the law of the conditional excluded middle) and that God can access that truth value. (Blake T. Ostler, Exploring Mormon Thought, vol. 1: The Attributes of God [Salt Lake City: Greg Kofford Books, 2001], 170-71)