Skip to content

[flang] Incorrect resolution of defined assignment #142151

@DanielCChen

Description

@DanielCChen

Consider the following code:

module m
   type com2
      integer i
      contains
         procedure :: c2a
         generic :: assignment(=) => c2a
   end type

   type, extends(com2) :: c_com2
      integer :: j
      contains
         procedure :: c2a => cc2a
   end type

   contains

      impure elemental subroutine c2a ( a, b )
         class(com2) , intent(out) :: a
         class(com2) , intent(in)  :: b

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

      end subroutine

      impure elemental subroutine cc2a ( a, b )
         class(c_com2) , intent(out) :: a
         class(com2) , intent(in)  :: b

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

         select type ( b )
            type is ( c_com2 )
               a%j = b%j + 1
         end select

      end subroutine

end module

program genericAssignmentDtIntrinAssgn037
  use m

   type container
      type(c_com2) :: cc21
   end type
   type(container) :: c1

   c1 = container(c_com2(14,15))
   print *, c1%cc21%i, c1%cc21%j

end program

Expected behavior:

> a.out
 in cc2a
 15 16

Flang outputs:

> a.out
 in c2a
 15 15

The component cc21 of type container is of type c_com2, so the component assignment should invoke the defined assignment of type c_com2rather than it's base typecom2`.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions