protected function resolveReturnType(Type $type, \Closure $resolver) : Type {
        if ($type instanceof UnionType) {
            $old = $type->getTypes();
            $new = [];
            foreach ($old as $subtype)
                $new[] = $resolver($subtype);
            return ($old===$new) ? $type : new UnionType($new);
        }
        return $resolver($type);
    }