If your gut is giving you a hard time, eating a whole bunch of spicy food and a pot brownie for dessert may sound like the worst idea in the world. But as counterintuitive as that might sound, new research suggests that your body might find this combo a salve for an irritated digestive tract.

Researchers with the University of Connecticut School of Medicine have discovered a surprising new function for chemicals found in hot peppers and marijuana in calming inflammation in the digestive tract, which could lead to new treatments for Type 1 diabetes, colitis, and other disorders that put the gut function out of whack. The study was published Monday in the Proceedings of the National Academy of Sciences.

Here’s how it works: Capsaicin, the chemical that gives hot peppers their heat, binds to special receptors in your digestive tract, and the result of this holy union is the production of a chemical called anandamide, an endogenous cannabinoid and chemically similar to the stuff in weed that gets you high — but produced from within your own body.

Anandamide, as it turns out, binds to another receptor in your digestive tract, stimulating the production and function of a certain type of white blood cell called a macrophage that lowers immune response and therefore limits inflammation. When researchers fed hot chilies to mice with Type 1 diabetes, they had a protective effect that essentially cured the animals of the disease. Giving the mice anandamide directly produced the same effect.

Eating marijuana products would likely deliver the same result, and it’s something researchers will be investigating.

“I’m hoping to work with the public health authority in Colorado to see if there has been an effect on the severity of colitis among regular users of edible weed,” says senior author Pramod Srivastava. “If the epidemiological data shows a significant change [since marijuana legalization in 2012], that would make a testable case that anandamide or other cannabinoids could be used as therapeutic drugs to treat certain disorders of the stomach, pancreas, intestines, and colon.”

The same receptors that cannabinoids binds to in the gut also exist in your brain, and it is activity here that ultimately gets you stoned. Why these receptors in the brain exist at all remains a medical mystery, but this new research unlocks a piece of the puzzle.

This study shows for the first time a major immune function for cannabinoids, and it could be that your digestive system and your nervous system are engaged in a bit of a biological conversation based on these shared receptors, Srivastava posits.

This anti-inflammatory property could help explain why spicy foods have been statistically linked to longer lifespans in China.

Eating a hot curry for dinner with a weed cookie for dessert might be just what the doctor ordered. Just don’t get confused and put hot peppers in your bong instead — that’s still stupid.