11590Srgrimes! { dg-do compile } 21590Srgrimes! 31590Srgrimes! PR fortran/37336 41590Srgrimes! 51590Srgrimes! Started to fail when finalization was added. 61590Srgrimes! 71590Srgrimes! Contributed by Ian Chivers in PR fortran/44465 81590Srgrimes! 91590Srgrimesmodule shape_module 101590Srgrimes 111590Srgrimes type shape_type 121590Srgrimes integer :: x_=0 131590Srgrimes integer :: y_=0 141590Srgrimes contains 151590Srgrimes procedure , pass(this) :: getx 161590Srgrimes procedure , pass(this) :: gety 171590Srgrimes procedure , pass(this) :: setx 181590Srgrimes procedure , pass(this) :: sety 191590Srgrimes procedure , pass(this) :: moveto 201590Srgrimes procedure , pass(this) :: draw 211590Srgrimes end type shape_type 221590Srgrimes 231590Srgrimesinterface assignment(=) 241590Srgrimes module procedure generic_shape_assign 251590Srgrimesend interface 261590Srgrimes 271590Srgrimescontains 281590Srgrimes 291590Srgrimes integer function getx(this) 301590Srgrimes implicit none 311590Srgrimes class (shape_type) , intent(in) :: this 321590Srgrimes getx=this%x_ 331590Srgrimes end function getx 341590Srgrimes 351590Srgrimes integer function gety(this) 361590Srgrimes implicit none 372537Spst class (shape_type) , intent(in) :: this 382537Spst gety=this%y_ 392537Spst end function gety 402537Spst 412537Spst subroutine setx(this,x) 422537Spst implicit none 432537Spst class (shape_type), intent(inout) :: this 442537Spst integer , intent(in) :: x 452537Spst this%x_=x 462537Spst end subroutine setx 471590Srgrimes 4867467Sru subroutine sety(this,y) 491590Srgrimes implicit none 501590Srgrimes class (shape_type), intent(inout) :: this 511590Srgrimes integer , intent(in) :: y 521590Srgrimes this%y_=y 5387628Sdwmalone end subroutine sety 541590Srgrimes 5587628Sdwmalone subroutine moveto(this,newx,newy) 5672109Scharnier implicit none 5787628Sdwmalone class (shape_type), intent(inout) :: this 581590Srgrimes integer , intent(in) :: newx 5987628Sdwmalone integer , intent(in) :: newy 6087628Sdwmalone this%x_=newx 6187628Sdwmalone this%y_=newy 621590Srgrimes end subroutine moveto 631590Srgrimes 641590Srgrimes subroutine draw(this) 651590Srgrimes implicit none 661590Srgrimes class (shape_type), intent(in) :: this 671590Srgrimes print *,' x = ' , this%x_ 681590Srgrimes print *,' y = ' , this%y_ 691590Srgrimes end subroutine draw 702537Spst 712537Spst subroutine generic_shape_assign(lhs,rhs) 722537Spst implicit none 732537Spst class (shape_type) , intent(out) , allocatable :: lhs 741590Srgrimes class (shape_type) , intent(in) :: rhs 751590Srgrimes print *,' In generic_shape_assign' 7623693Speter if ( allocated(lhs) ) then 7723693Speter deallocate(lhs) 781590Srgrimes end if 791590Srgrimes allocate(lhs,source=rhs) 801590Srgrimes end subroutine generic_shape_assign 811590Srgrimes 8223693Speterend module shape_module 8323693Speter 8423693Speter! Circle_p.f90 8511759Sache 8623693Spetermodule circle_module 871590Srgrimes 8864775Sbrianuse shape_module 891590Srgrimes 901590Srgrimestype , extends(shape_type) :: circle_type 911590Srgrimes 9214631Solah integer :: radius_ 9374586Sache 941590Srgrimes contains 951590Srgrimes 9692920Simp procedure , pass(this) :: getradius 9792920Simp procedure , pass(this) :: setradius 9892920Simp procedure , pass(this) :: draw => draw_circle 9992920Simp 1001590Srgrimesend type circle_type 10187229Smarkm 1022589Spst contains 1031590Srgrimes 1041590Srgrimes integer function getradius(this) 1051590Srgrimes implicit none 1061590Srgrimes class (circle_type) , intent(in) :: this 1071590Srgrimes getradius=this%radius_ 1082589Spst end function getradius 1092537Spst 11024360Simp subroutine setradius(this,radius) 1111590Srgrimes implicit none 1121590Srgrimes class (circle_type) , intent(inout) :: this 1131590Srgrimes integer , intent(in) :: radius 1141590Srgrimes this%radius_=radius 1151590Srgrimes end subroutine setradius 1161590Srgrimes 1171590Srgrimes subroutine draw_circle(this) 1181590Srgrimes implicit none 1191590Srgrimes class (circle_type), intent(in) :: this 1201590Srgrimes print *,' x = ' , this%x_ 1211590Srgrimes print *,' y = ' , this%y_ 1221590Srgrimes print *,' radius = ' , this%radius_ 1231590Srgrimes end subroutine draw_circle 1242537Spst 1252537Spstend module circle_module 1262537Spst 1272537Spst 1282537Spst! Rectangle_p.f90 1292537Spst 13014631Solahmodule rectangle_module 13114631Solah 13214631Solahuse shape_module 1331590Srgrimes 1341590Srgrimestype , extends(shape_type) :: rectangle_type 13527169Scharnier 1361590Srgrimes integer :: width_ 1371590Srgrimes integer :: height_ 1382589Spst 1392589Spst contains 1402589Spst 14127169Scharnier procedure , pass(this) :: getwidth 14227169Scharnier procedure , pass(this) :: setwidth 14327169Scharnier procedure , pass(this) :: getheight 14427169Scharnier procedure , pass(this) :: setheight 14527169Scharnier procedure , pass(this) :: draw => draw_rectangle 14627169Scharnier 14727169Scharnierend type rectangle_type 14827169Scharnier 1492589Spst contains 1502589Spst 1512589Spst integer function getwidth(this) 1522589Spst implicit none 15327169Scharnier class (rectangle_type) , intent(in) :: this 1542589Spst getwidth=this%width_ 15546662Sobrien end function getwidth 15687229Smarkm 1572589Spst subroutine setwidth(this,width) 15846662Sobrien implicit none 15946662Sobrien class (rectangle_type) , intent(inout) :: this 16046662Sobrien integer , intent(in) :: width 16146662Sobrien this%width_=width 16246662Sobrien end subroutine setwidth 16346662Sobrien 16446662Sobrien integer function getheight(this) 16546662Sobrien implicit none 16646662Sobrien class (rectangle_type) , intent(in) :: this 16746662Sobrien getheight=this%height_ 16811811Sache end function getheight 16911759Sache 1702589Spst subroutine setheight(this,height) 1712589Spst implicit none 1722589Spst class (rectangle_type) , intent(inout) :: this 1732589Spst integer , intent(in) :: height 1742589Spst this%height_=height 1752589Spst end subroutine setheight 1762589Spst 1772589Spst subroutine draw_rectangle(this) 17887229Smarkm implicit none 1792589Spst class (rectangle_type), intent(in) :: this 1802589Spst print *,' x = ' , this%x_ 1812589Spst print *,' y = ' , this%y_ 1822589Spst print *,' width = ' , this%width_ 1832589Spst print *,' height = ' , this%height_ 1842589Spst 1852589Spst end subroutine draw_rectangle 1862589Spst 1871590Srgrimesend module rectangle_module 1881590Srgrimes 1891590Srgrimes 1901590Srgrimes 1911590Srgrimesprogram polymorphic 1921590Srgrimes 1931590Srgrimesuse shape_module 1941590Srgrimesuse circle_module 1951590Srgrimesuse rectangle_module 1961590Srgrimes 1971590Srgrimesimplicit none 1981590Srgrimes 1991590Srgrimestype shape_w 2001590Srgrimes class (shape_type) , allocatable :: shape_v 2011590Srgrimesend type shape_w 2021590Srgrimes 2031590Srgrimestype (shape_w) , dimension(3) :: p 2041590Srgrimes 2051590Srgrimes print *,' shape ' 2061590Srgrimes 2071590Srgrimes p(1)%shape_v=shape_type(10,20) 2081590Srgrimes call p(1)%shape_v%draw() 2091590Srgrimes 21048566Sbillf print *,' circle ' 2111590Srgrimes 2121590Srgrimes p(2)%shape_v=circle_type(100,200,300) 2131590Srgrimes call p(2)%shape_v%draw() 2141590Srgrimes 21548566Sbillf print *,' rectangle ' 21623693Speter 2171590Srgrimes p(3)%shape_v=rectangle_type(1000,2000,3000,4000) 2181590Srgrimes call p(3)%shape_v%draw() 2191590Srgrimes 2201590Srgrimesend program polymorphic 2211590Srgrimes