The dihedral effect is an opposing rolling moment induced by a sideslip. When an airplane is disturbed from wings level, it immediately starts to slip "downhill", slide sideways toward the low wing, in effect. The vertical fin starts to react to this after a certain amount of slip has developed, to realign the airplane with the airstream, weathervaning it more or less, and the airplane turns (while going downhill, unless you increase angle-of-attack.
The fin needs to be small enough to allow this slip to develop a small amount for dihedral effect to work. The slip generates the rolling moment to restore level flight, and there's your lateral stability. If the fin is too big, it will start to weathervane the plane too soon, and dihedral effect can't develop strongly enough to roll the wings level, and the plane instead wants to spiral right away.
Anyway, you get dihedral effect from three configurations that can generate rolling moments from sideslip: geometric dihedral (wings angled up), the T intersection of a high wing configuration (where diagonal flow is unhindered across the roof, but is blocked by the fuselage below, increasing the lift on the low wing), and wing sweep. High wing airplanes may get enough dihedral effect just from the T configuration, and the wing can be straight, especially if maneuvering is a higher priority than cruising.
The Canadair CL-215 has no geometric dihedral; the T junction is sufficient for a water bomber that makes maneuvering a higher priority than cruising (when the CL-415 was tested, the flat engine nacelles sticking up were like fences that inhibited lateral flow, as if there was fuselage extending above the wings, and resulted in killing off much of the dihedral effect of the T junction; the odd turned up wingtips of the 415 are "dihedral plates" a band-aid designed to restore dihedral effect for the desired lateral stability).
In the 172, (and probably most high wing unswept aircraft designed for cruising), Cessna wanted to supplement the dihedral effect of the T configuration with a bit of geometric dihedral to get the total effect they wanted. The geometric dihedral is probably about half the angle of a low wing airplane, since no more is necessary thanks to the high wing placement. High wing transports with unswept wings, like the Dash 8 family, have a small amount of geometric dihedral as well, maybe a degree or so outboard of the engines, to supplement the dihedral effect of the T configuration.
This brings us to wing sweep. Wing sweep generates really strong roll due to sideslip (something you find out pretty fast when you take a jet initial type rating), so there is strong dihedral effect from sweep. When the wing is at the top, you have the dihedral effect of the T configuration, plus the dihedral effect of the wing sweep, and you get way too much roll due to sideslip for desirable lateral stability and dutch roll characteristics. To reduce the excessive dihedral effect, they use anhedral to reduce the total roll/yaw coupling effects to a desirable level.
That's why almost all high wing aircraft with swept wings have anhedral (to basically cancel out some of the effect of the sweep), whereas high wing airplanes with unswept wings have zero or mildly positive geometric dihedral. Likewise, a low wing swept wing jet will have less dihedral than it would have if the wings were unswept.