Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Bad initialization expression using extended types

$
0
0

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  

 


Viewing all articles
Browse latest Browse all 3270

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>