Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26758 Discussions

internal type constructor vs user-defined type constructor

Blane_J_
New Contributor I
104 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 I
104 Views

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

Blane_J_
New Contributor I
104 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

 

FortranFan
Honored Contributor II
104 Views

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

Steve_Lionel
Black Belt Retired Employee
104 Views

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

Blane_J_
New Contributor I
104 Views

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

Reply