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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Failure on `fir.convert`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:fir-hlfir
      </td>
    </tr>

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

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

<pre>
    Consider the following code:
```
module m
    type base
        integer(8), allocatable :: id
    end type

    type container
        type(base), allocatable :: b
    end type

    interface container
        procedure containerObjWithDefault
    end interface

    contains

 type(container) function containerObjWithDefault ()
        allocatable containerObjWithDefault

    end function
end module

program main
use m
    type(container), allocatable :: co1(:,:), co2(:,:)

    logical(8), allocatable :: l1(:,:)

    co2 = merge (container(), co1, l1)

end
```

Flang failed at the compile time `fir.covert`
```
error: loc("/home/cdchen/temp/t.f":28:5): 'fir.convert' op invalid type conversion'!fir.ref<!fir.type<_QMmTcontainer{b:!fir.box<!fir.heap<!fir.type<_QMmTbase{id:!fir.box<!fir.heap<i64>>}>>>}>>' / '!fir.box<!fir.heap<!fir.type<_QMmTcontainer{b:!fir.box<!fir.heap<!fir.type<_QMmTbase{id:!fir.box<!fir.heap<i64>>}>>>}>>>'
error: verification of lowering to FIR failed
```

Note: this is a reducer that would not execute as many variables are not defined, but it should compile successfully.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVcGOpDYQ_RpzKU0LbHqgDxyY7iDlkESJIuUYGbsMXhm7ZZuenb-P7GGn2dmdVY7bQm2Mq957uF4ZHoKeLGJHjk_keCn4Gmfnuwu3Gs35PKMtRidfurOzQUv0EGcE5Yxxz9pOIJxEwnpS9uSx3K6yX5xcDcJCyh4AIL5cEUYecJunn7YRJ_SEti2hJ0LPwI1xgkc-GoQEyXrQcstAKzNK4tlhCmcj1xb9DjiH0TbTfQg8foibdH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