A top Irish court has ruled a key plank of the country's anti-narcotics laws illegal, temporarily legalizing the possession of many street stimulants and hallucinogens.

The government scrambled to close the surprise loophole Tuesday with an emergency late-night bill.

Health Minister Leo Varadkar said the government hoped its patchwork bill would be signed into law by Wednesday. He cautioned drug dealers that, despite the ruling, they would be arrested if caught by police dealing drugs overnight.

Ireland's Court of Appeal ruled that an executive order outlawing more than 100 drugs was unconstitutional, because lawmakers had not voted in support of the measure.

The court ruled in favor of a man convicted in 2012 of possessing a drug that the government had placed on its outlawed substances list the previous year.