fix Issue 12523 - wrong type deduced for foreach ref argument

- take storage class const/immutable/inout from already declarared
  foreach argument