Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
2 Views

internal type constructor vs user-defined type constructor

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
Highlighted
Valued Contributor II
2 Views

The interface declares var as

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

0 Kudos
Highlighted
New Contributor I
2 Views

Thanks andrew. Unfortunately

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
Highlighted
Valued Contributor III
2 Views

Looks like a compiler bug,

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

0 Kudos
Highlighted
Black Belt
2 Views

I agree - the definition of

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

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
New Contributor I
2 Views

Thanks FortranFan and Steve,

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

0 Kudos