Skip to content

[flang] Another variation of defined assignment resolution error #142414

@DanielCChen

Description

@DanielCChen

Consider the following code:

module m

   type base
      integer :: i
      contains
         procedure :: bassgn
         generic :: assignment(=) => bassgn
   end type

   type, extends(base) :: child
      integer :: j
      contains
         procedure :: cassgn
         generic :: assignment(=) => cassgn
   end type

   type container
      class(child), allocatable :: c1(:)
   end type

   contains

      impure elemental subroutine bassgn ( a, b )
         class(base), intent(out) :: a
         type(base), intent(in)   :: b

         print*, " in bassgn."
         a%i = b%i + 1

         select type ( a )
            type is ( child )
               a%j = b%i + 2
         end select

      end subroutine

      impure elemental subroutine cassgn ( a, b )
         class(child), intent(out) :: a
         type(child), intent(in)   :: b

         print*, " in cassgn."
         a%i = b%i + 2
         a%j = b%j + 2

      end subroutine

end module

program genericAssignmentDtIntrinAssgn029
   use m

   type(container) :: c1

   allocate ( c1%c1(-100:-98) )

   c1 = container( (/ child(4,5), child(6,7), child(8,9) /) )

end program

Expected output:

  in cassgn.
  in cassgn.
  in cassgn.

Flang outputs:

  in bassgn.
  in bassgn.
  in bassgn.

The component c1 of type container has declare type of child. The defined assignment subroutine cassgn should be called instead of the one of type base.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions