Humans have a love-hate relationship with sunlight: On the one hand, it provides energy for the plants we eat, keeps us from freezing to death, and gives us healthy doses of vitamin D. On the other, UV rays from the sun can destroy the appearance of our skin and put us at risk for deadly melanoma. It’s well-known that tanning ups the chances of skin cancer, but a new study suggests that those who regularly soak up the rays may actually be living longer than people who avoid the sun.

Researchers from Karolinska University Hospital and Lund University in Sweden analyzed information on 29,518 Swedish women of all ages, whom they followed for 20 years, to draw their conclusions. While the researchers’ central objective was to compare the differences in the main cause of death for women with various levels of sun exposure, they found some unexpected results in terms of life expectancy. Women who avoided the sun had a life expectancy 0.6 to 2.1 years shorter than those in the group with the highest sun exposure.

The data showed a decrease in heart disease and deaths unrelated to cancer and heart disease for those who got the most sun. Strikingly, nonsmokers who avoided sunlight had a similar life expectancy to smokers in the highest exposure group — an indication that hiding from the sun is a risk factor for death similar in caliber to smoking.

“Guidelines being too restrictive regarding sun exposure may do more harm than good for health,” said Dr. Pelle Lindqvist, lead author of the study, in a press release.

What caused the association between sun exposure and longer life expectancy wasn’t clear. Possible culprits could be vitamin D, another UV-related mechanism, or some other bias. It will take additional research to determine which is responsible.

Sunbathing’s association with skin cancer is unquestionable, as about 90 percent of nonmelanoma and 86 percent of melanoma skin cancer cases can be attributed to UV radiation exposure. Though skin cancer is widespread and costly, it does not usually lead to death. In the study, women with high sun exposure had increased survival compared to their sun-shy peers, but due to their extended lifespans, their likelihood of death from cancer increased.

Source: Lindgvist P, Epstein E, Nielsen K, Landin-Olsson M, Ingvar C, Olsson H. Avoidance of sun exposure as a risk factor for major causes of death: a competing risk analysis of the Melanoma in Southern Sweden cohort. J Intern Med. 2016.