Fix for #5027 -- generate a deprication warning for dynamic lookup
This fix implements the same logic as Nick & Paul's patch in a different way.
There aren't any tests yet and I'm still working out if I agree with the
handling of some edge cases, so this should be considered premliminary.