Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28989 Discussions

Bad initialization expression using extended types

Jacob_Williams
New Contributor II
989 Views

I have a question.  See code below.  I'm using a variable in one type in an initialization expression for another type.  The first block compiles fine, as expected.  The second one (which is using an extended type that contains the same data) throws a "error 7169: Bad initialization expression [BLAH]" if I don't use the var%base_type%name form to access the variable.  Is this correct or a compiler bug?  I can normally use var%name in other circumstances.  Is there a reason that this is not allowed in this context?

program main
    
    implicit none
    
    type :: blah
        character(len=100) :: str = ''
    end type blah

    block
        type :: extended_type
            integer              :: id    = 0
            character(len=100)   :: name  = ''
        end type extended_type
        type(extended_type),parameter :: var = extended_type(id=1, name='var')
        type(blah),parameter :: blah_var = blah(str=var%name)         !compiles fine
    end block

    block
        type,abstract  :: base_type
            integer              :: id    = 0
            character(len=100)   :: name  = ''
        end type base_type
        type,extends(base_type)  :: extended_type
        end type extended_type
        type(extended_type),parameter :: var = extended_type(id=1, name='var')
        type(blah),parameter :: blah_var1 = blah(str=var%base_type%name)      !compiles fine
        type(blah),parameter :: blah_var2 = blah(str=var%name)                !error 7169: bad initialization expression
    end block
  
end program main  

 

0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
989 Views

What happens when you change name in base_type to nameB? (and change references to it too)

Jim Dempsey

0 Kudos
FortranFan
Honored Contributor III
989 Views

Looks like a compiler bug to me.  Hmm.. the code as shown generates an internal compiler error (ICE) with gfortran 5.0!

 

0 Kudos
Jacob_Williams
New Contributor II
989 Views

Jim: same problem occurs if name is changed to nameb.

0 Kudos
Kevin_D_Intel
Employee
989 Views

The same error occurs Jim. I tried a few other changes without any success either. I escalated this to Development (see internal tracking id below) and will keep you posted on their analysis.

(Internal tracking id: DPD200360691)

0 Kudos
Reply