Use local cache more often

Use local cache when there are unbound type variables and where clauses are in scope.

Fixes #18209.

r? @nick29581 
Could you create a type alias for uint?