Protestors march to City Hall in solidarity with Freddie Gray after it was announced in May that criminal charges would be brought against all six officers involved in his arrest and transport. (Jabin Botsford/The Washington Post)

Attorneys for William G. Porter on Thursday sought to convince Maryland’s highest court that it would be unconstitutional to force the Baltimore police officer to testify against colleagues who also are charged in the death of Freddie Gray.

During arguments before the Maryland Court of Appeals, attorney Gary Proctor said that the officer should be treated either as a witness or as a defendant. To treat him as both would compromise Porter’s right to a fair trial, he said.

“They want to have their cake, and they want to eat it too,” Proctor told the seven judges in the wood-paneled chambers in Annapolis.

But the state has argued that Porter’s account is key to the prosecution’s case against his colleagues and has promised that anything he said would not be used against him during his retrial. Just because Porter is a defendant, prosecutors said, doesn’t change the fact that he was also a witness to the tumultuous events leading to Gray’s death.

Porter’s status as a witness “does not expand or contract with the filing of a charging document,” said Carrie Williams, a prosecutor in the state attorney general’s office who argued the case on behalf of Baltimore prosecutors.

The court’s ruling could ultimately determine the strength of the prosecution’s cases­ against several of the officers charged in Gray’s death. City prosecutors have previously said that their cases would be “gutted” without Porter’s testimony.

The judges asked pointed questions of both sides during Thursday’s hearing, but it was unclear what the court will decide or when it will issue a ruling. However, the court, which must issue a decision before the end of its term in September, is expected to act quickly as any delay would further hold up the officers’ trials, which have been postponed because of pending appeals.

Baltimore prosecutors contend that the six officers who face charges in the case acted callously and violated department policy, leading to the fatal neck injury that Gray suffered inside a police van April 12. The 25-year-old died a week after his arrest, and the death sparked protests and riots in the city.

Porter, whose first trial ended in December with a hung jury, is scheduled for a retrial in June.

A Baltimore Circuit Court judge ruled in January that Porter would have to testify against two of his fellow officers — Caesar Goodson Jr. and Alicia D. White — but not against the other three — Edward M. Nero, Garrett E. Miller and Brian W. Rice. The Court of Appeals’ ruling would determine whether Porter must take the stand against any or all of the officers.

The appeal presents an unprecedented legal question in the state, the attorneys told the court, with little case law elsewhere in the country to guide the matter.

“This is the first time that we’ve really had a defendant as a witness,” said Judge Lynne A. Battaglia.

Porter’s attorneys contend that the immunity that prosecutors would offer should not apply to someone with a pending homicide trial.

Subjecting Porter to be a witness at five trials, Proctor argued, would allow prosecutors to learn details that could be used against the officer at his own trial. Even if the material wasn’t used directly, it could still influence the thought process and strategy that prosecutors would employ against Porter as a defendant.

“What is known cannot be unknown,” Proctor said. “Not testifying is the only guarantee that they got what they got by their own ­devices.”

But prosecutors told the court that any additional evidence the state seeks to use against Porter at his retrial would come with a “heavy burden.” The state would have to show at a hearing that the material didn’t stem from his immunized testimony, Williams said.

“Sooner or later we must all sit down to a feast of consequences,” Williams said, citing Robert Louis Stevenson. That consequence, she said, was to painstakingly prove evidence came independent of Porter’s immunized testimony and “it’s a risk that the state has to evaluate.”