The Pennsylvania Supreme Court, in a stunning ruling on Tuesday, will allow the disgraced comedian and actor Bill Cosby to appeal his sexual assault convictions.

The state’s high court said it’ll hear arguments on whether it was proper for prosecution witnesses to say Cosby had also drugged them and if incriminating statements made by the defendant, during a civil lawsuit, should have been used against him in criminal court.

Cosby, 82, has been behind bars for nearly two years after a Montgomery County jury convicted him in 2018 of drugging and sexually assaulting a woman in 2004. He’s serving a three- to 10-year sentence.

The high court said allowing the testimony from witnesses about “allegations of uncharged misconduct involving sexual contact” could have been more prejudicial than probative.

Pennsylvania’s Supreme Court also wants to hear arguments on the fairness of using civil trial statements made by Cosby against him in criminal court.

Lawyers for Cosby have long argued that a previous Montgomery County district attorney promised not to prosecute the comedian for his contacts with former Temple University employee Andrea Constand.

With that perceived immunity, Cosby allowed himself to be questioned during depositions in 2005 and 2006 in a lawsuit by Constand, defense lawyers have said.

Before settling for $3.4 million, Cosby admitted to giving drugs to various women before having sex.