<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/99065>99065</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang] failed lowering for sequence association of derived-type
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          bcornille
      </td>
    </tr>
</table>

<pre>
    Reproducer: (contained_subroutine_flatten.f90)
```
program flattening_test
  use iso_fortran_env, only : int32
  implicit none

  type mytype
 integer(int32) :: k
  end type mytype

  class(mytype), allocatable :: multidim_array(:,:)
  integer(int32), parameter :: num = 4
 integer(int32) :: i

  allocate(mytype :: multidim_array(num,num))
 call reinterpret_1d(multidim_array,num*num)

contains

 subroutine reinterpret_1d(array, n)
    integer(int32), intent(in) :: n
    type(mytype), intent(inout) :: array(n)
    integer(int32):: j
    do j = 1, n
      array(j)%k = j
    enddo
  end subroutine reinterpret_1d

end program flattening_test
```
Error:
```
>> flang-new contained_subroutine_flatten.f90
error: loc("/home/bcornill/Reproducers/SWDEV/temp/contained_subroutine_flatten.f90":14:3): 'fir.rebox' op result type and shape operand ranks must match
error: verification of lowering to FIR failed
```
Changing either `class(mytype), allocatable :: multidim_array(:,:)` to `type(mytype), allocatable :: multidim_array(:,:)` or `type(mytype), intent(inout) :: array(n)` to `class(mytype), intent(inout) :: array(n)` resolves the error.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVV2PqzYQ_TXmxdoITAjwwEO6WaS-3krtY2TsAbxrbDo2uc2_rwzkY7-6q-pKURCemTPHx2cMd051BqAi2W8kO0R88r3FqhEWjdIaosbKc_UDRrRyEoAk3VPCCmGN58qAPLqpQTt5ZeDYau49mE1bxoSVJD6QeE928fqbX0e0HfKBrqnKdEcPzi9BSicHVDl7bC165OYI5kTYI7VGn2norIxP2SVZDaNWQnlqrIG12xry5xHocA6PdUkZDx0gYcWCwcoAGDBfLkVg5PvCS1Bo7hxhxRpjZeDFtbaCe95ouKANk_ZKquHIEfmZsCKss8f5v7wyf0cmoI0c-QAe8IJlpoGS9EC3X-5BvSa78oIr30_ZmWkg7HH-L28EBdeaIoR-OCL4YyID1JvipWy_Ft8RWM3hXpG6-eQ98gWQmjuRPpMprBo_L94pYG5lywG9Pqm7Ijv5u7qrEF91XtKfbznS0uf5eJKF-TVAr6DPc_fsZU67KwUjpb233efi3EkYEv9zft7M2hOiDfP6YZCkTyR9CjimezDwk3450QuHFZNqK4K5GSOs7u0AhNWXO4Ow-nZfOMLqP_46PP1JWO1hGAmrv747GEn3yZak-3RRnhKWtwo3CI39h7Cc2pEiuEn7ZWB5kLDnI1A7AoY35ObF0WFyng7ci_4N-xOgapXgXllDbUu1_QmoTEe9pfXvP2jLlQb5oXCPPTddSAXl-zCru_jX3A27OHQnu_gj__4fNIufoX1vGq6EPtzftzEQnNUncNT3QOcT2ESySmWZljyCKslZkmRJnBRRX0GRb3kptq1ku7LNY1lI1jTlLudpxotSRKpiMdvGebJL8jRO0k2bZQmItMwzWWzTXUK2MQxc6Y3Wp2FjsYuUcxNUZRnvskjzBrSbv3WMzd4PZssOEVYh_6GZOke2sVbOuxuCV17PH8ilIjus_rjZprVIHfw9gRFAuXNWqKu3JKA6gXwI2kUT6qr3fnTzMdWE1Z3y_dRshB0Iq0PL9fEwon0G4Qmr5x2EQVo2carYvwEAAP__yYZctw">