Extension and assigning of type results in GNU internal compiler error

I have a module where I define two types, where one extends the other. In this particular case, I first define a variable of the base-type and then convert it to the extended type. However, my current implementation results in an internal compiler error on gfortran GNU 10.3.0:

module my_test_module

  type :: baseType
    contains
    procedure :: &
      asExtended => baseType_asExtended
  end type baseType

  type, extends(baseType) :: extendedType
  end type extendedType
  contains

  function baseType_asExtended(self) result(extended)
    class(baseType), intent(in), target     :: self
    class(extendedType), pointer            :: extended

    select type(self)
      class is (extendedType)
        extended => self
      class default
        nullify(extended)
    end select
  end function baseType_asExtended

end module my_test_module

Program TEST
  use my_test_module
  implicit none

  class(baseType), pointer :: &
    generic_object
  type(extendedType) :: &
    extended_object

  allocate(extendedType::generic_object) ! compiler error happens without this line as well
  extended_object = generic_object%asExtended()
End Program TEST

error message:

   34 |   extended_object = generic_object%asExtended()
      |                                               1
internal compiler error: in conv_function_val, at fortran/trans-expr.c:4158
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.

The same code has no problems compiling on intel’s ifort 2021.6.0 20220226.

Modifying the main program TEST as following stops the error from occurring on GNU:

Program TEST
  use my_test_module
  implicit none

  class(baseType), pointer :: &
    generic_object
  type(extendedType) :: &
    extended_object
  type(extendedType), pointer :: &
    generic_object_pointer

  allocate(extendedType::generic_object)
  generic_object_pointer => generic_object%asExtended()
  extended_object = generic_object_pointer
End Program TEST

Why am I required to perform this extra step here on GNU? Is this something that could be addressed in the near future?

1 Like

@d.mentock ,

As you will know, an internal compiler error is understood to be a compiler bug.

Please refer to the section in this GNU org link on reporting bugs:
https://gcc.gnu.org/wiki/GFortran#Reporting_bugs