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

internal type constructor vs user-defined type constructor

Blane_J_
New Contributor I
340 Views

Hi, I‘ve encountered a derived-type constructor selection issue and the compiler reported an error which seemed non-relevant. The sample code is as follows:

module test
    implicit none
    
    private
    public :: var

    type :: tp
        private
        integer(8) :: var1
        logical    :: var2 = .false.
    end type tp
    
    interface tp
        module procedure :: init
    end interface tp
    
    interface
        module function init(var)
            type(tp)            :: init
            integer, intent(in) :: var
        end function init
    end interface

    integer(8), parameter :: default = 10
    type(tp),   parameter :: var     = tp(default, .false.)
   
end module test

The error message is:

error #6050: This parameter was defined too late.   [DEFAULT]

If tp and init interfaces are removed, the code can be compiled with no errors. Appreciate any help.

0 Kudos
5 Replies
andrew_4619
Honored Contributor II
340 Views

The interface declares var as integer and not integer(8) but if that is the problem the message is strange!

0 Kudos
Blane_J_
New Contributor I
340 Views

Thanks andrew. Unfortunately it's not the problem. As you suggested, I made some corrections to the sample.

And in addition, if the default value is set literally, it's all right.

module test
    implicit none
    
    private
    public :: var

    type :: tp
        private
        integer(8) :: var1
        logical    :: var2 = .false.
    end type tp
    
    interface tp
        module procedure :: init
    end interface tp
    
    interface
        module function init(var)
            type(tp)               :: init
            integer(8), intent(in) :: var
        end function init
    end interface

    integer(8), parameter :: default = 10_8
    !type(tp),   parameter :: var     = tp(default, .false.) ! <--- Bad.
    type(tp),   parameter :: var     = tp(10_8,    .false.) ! <--- Good.
    
end module test

 

0 Kudos
FortranFan
Honored Contributor II
340 Views

Looks like a compiler bug, deserving of submission at the Intel Online Service Center/

0 Kudos
Steve_Lionel
Honored Contributor III
340 Views

I agree - the definition of the user constructor init is confusing the compiler. I don't see anything wrong with the code.

0 Kudos
Blane_J_
New Contributor I
340 Views

Thanks FortranFan and Steve, I'll report it to OSC.

0 Kudos
Reply