Cast val when during the uniqueValue lookup.