What a dope.

Cops swarmed a San Diego building Tuesday when a man waved what appeared to be an assault rifle out of its window — only to discover it was a bong shaped like an AR-15.

Officers on patrol in the area of the residential Palms Hotel were put on high alert at 6:22 p.m. local time when a concerned witness “said they saw a guy pointing what appeared to be a rifle towards the officers” from a window, Officer Billy Hernandez of the San Diego Police Department told The Post Wednesday.

Authorities immediately formed a team, set up a perimeter around the area and stopped trolley traffic as they went up to the room to question and detain Justin Baxley, 22, and another woman who was inside.

But once inside the room, cops found the gold, gun-shaped glass bong inside a small refrigerator police said.

The pot-smoking device “had a realistic hand grip similar to an AR-15 rifle,” Hernandez said.

Baxley was charged with exhibiting an replica firearm in a threatening manner, authorities said.

The woman who was inside the room with Baxley at the time was released by cops without charge.

The Palms Hotel is a historic 70-unit residential hotel located directly in front of a trolley stop in the East Village.