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

Nested defined assignment not called with parameterized derived type

WileyOne
Novice
1,319 Views

Compiler: ifx (IFX) 2025.2.0

OS: Rocky Linux 8.10 (Green Obsidian)

 

I've found a bug at the intersection of parameterized derived types and defined assignment, specifically when nested 3 classes deep. In the following code, the print statement should display, but it does not.

module Classes_Header

    implicit none

    type :: class1
        integer :: ii
        contains
        generic, public :: assignment(=) => copy
        procedure, private :: copy
    end type

    type :: class2
        type(class1) :: myClass1
    end type

    type :: class3(n)
        integer, len :: n
        type(class2) :: myClass2
    end type

    contains

    subroutine copy(lhs,rhs)
        class(class1), intent(out) :: lhs
        class(class1), intent(in)  :: rhs

        lhs%ii = 7
        print *, 'copy was called - worked as expected'
    end subroutine

    function constructor() result(this)
        type(class3(4)) :: this

        this%myClass2%myClass1%ii = 42
    end function

end module

program main

    use Classes_Header

    implicit none
    type(class3(:)), allocatable :: myClass3

    myClass3 = constructor()

end program

Note that if class3 is not a parameterized derived type, the defined assignment is called as expected. This is true even if class3 remains an allocatable in the program main.

0 Kudos
3 Replies
WileyOne
Novice
1,296 Views

Note the similarities and differences between this and another issue I just updated. In both bugs, the defined assignment is not called. Here, the problem comes from the parameterized derived type, while the other issue is a nested class structure containing an `allocatable` class.

0 Kudos
Ron_Green
Moderator
1,292 Views

Thank you for sending this to us. The bug ID is CMPLRLLVM-68773


0 Kudos
WileyOne
Novice
925 Views

Three other cases to add here. They are subtle differences from my original post, but I wanted to make sure these edge cases were caught. In short, the defined assignment is neither called when class3 is a class-allocatable nor when it extends from an abstract class nor when it's a type with the same parameter; see the attached files for specifics. I appended "TypeAllocatable_OriginalPost" onto the name of the file above for clarity, but it is the same otherwise.

 

@Ron_Green, should I make separate issues for these bugs or leave them as part of this one?

 

0 Kudos
Reply