Fix a possible memory corruption bug when using val::as