Sexting minors is illegal, but having sex with them is okay, an Indiana Supreme Court has ruled.

Indiana high school teacher Sameer Thakar faces three years in prison for sending nude photographs to a 16-year old girl after the Supreme Court ruled earlier this week to reverse a lower court’s decision to throw out the case.

Thakar began texting the teenager in 2014, when he was 38. After a short period in which the girl told him she was underage, he then sent her images of his erect penis, court documents reveal.

He was charged with one count of felony dissemination of matter harmful to minors, but argued in court that the charge doesn’t make sense.

#AnthonyWeiner faced up to decade in prison, lawyers argued that he acted from "depths of an uncontrolled sickness” https://t.co/uFxM5eutP5pic.twitter.com/EwgtflQYR3 — RT America (@RT_America) September 25, 2017

In Indiana, it is legal for adults to have consensual sex with 16 year olds. It is illegal, however, for a person to knowingly send sexually explicit photographs to someone under 18, which is classed as disseminating material harmful to minors.

The court originally threw out the charges, explaining it was “patently illogical” that a man could have sex with a teenager, but not send them images. The case was appealed and ended up in Indiana’s Supreme Court.

The Supreme Court found the charges should be upheld, despite the “inconsistent” law. It found no conflict between the two rules, as both can be complied with at the same time.

25 wives & 146 kids: Rogue Mormon sect leaders convicted of polygamy https://t.co/m20dl1f1x7 — RT (@RT_com) July 25, 2017

“With respect to a 16-year-old, consensual sexual activity in person is permitted, the dissemination of a sexually explicit photograph (consensually or otherwise) is not,” Justice Mark Massa wrote.

Massa said the court interprets the text of the law, and that it’s up to state lawmakers to sort out the inconsistency.