Hi Anton,
No it is not conforming.
(1) Line 36 has an array constructor whose ac-values have different type
parameter values. When you have ac-values with different type parameter
values, you need to have a type-spec to specify what type parameter values
the array constructor should have. In this case inserting "CHARACTER(11)::"
would seem to be in order.
(2) At lines 40-42 the actual argument is T1 (or an extension thereof) with
MASS_KIND equal to KIND(0d0). However, the procedure expects T1 (or an
extension thereof) with MASS_KIND equal to KIND(0.0).
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of
Anton Shterenlikht
Sent: Monday, August 7, 2017 11:56 PM
To: [log in to unmask]
Subject: [COMP-FORTRAN-90] extensible types, type parameters, polymorphic
Is this program conforming?
module m
implicit none
type t1( mass_kind, nlen, number )
integer, kind :: mass_kind = kind(1.0)
integer, len :: nlen=1, number=1
character( len=nlen ) :: cname( number )
real( kind=mass_kind ) :: mass_g
end type t1
type, extends( t1 ) :: t2
real :: length_mm
end type t2
type, extends( t2 ) :: t3( slen )
integer, len :: slen
character( len=slen ) :: lname( number )
end type t3
contains
subroutine s( amph )
class( t1 ) :: amph(:)
integer :: i
do i = 1, size( amph )
if ( amph(i) % mass_g .gt. 3.0 ) write (*,*) amph(i) % cname
end do
end subroutine s
end module m
program z
use m
implicit none
integer, parameter :: arlen=4
type( t3( mass_kind=kind(1.0d0), nlen=50, number=3, slen=80 ) ) :: toad(
arlen )
integer :: i
toad % mass_g = real( (/ (i, i=1, size(toad)) /), kind=kind(1.0d0) )
write (*,*) toad % mass_g
do i=1, arlen
toad(i) % cname(:) = "unnamed"
end do
toad(arlen) % cname(:) = (/ "common toad", "warty toad", "slow toad" /)
do i=1, arlen
write (*,*) toad(i) % cname
end do
call s( toad % t1 )
call s( toad % t2 )
call s( toad )
end program z
I think yes.
Compiler 1 rejects it with:
etdtp.f90(41): error #6633: The type of the actual argument differs from the
type of the dummy argument. [T1]
call s( toad % t1 )
-------------------^
etdtp.f90(42): error #6633: The type of the actual argument differs from the
type of the dummy argument. [T2]
call s( toad % t2 )
-------------------^
etdtp.f90(43): error #6633: The type of the actual argument differs from the
type of the dummy argument. [TOAD]
call s( toad )
------------^
which seems wrong to me.
Compiler 2 rejects with:
use m
^
ftn-925 crayftn: ERROR Z, File = etdtp.f90, Line = 27, Column = 5
"CNAME" has been use associated, therefore it must not be redeclared as
variable length character.
^
ftn-1014 crayftn: ERROR Z, File = etdtp.f90, Line = 27, Column = 5
Character object "LNAME" has nonconstant bounds. It can only be declared
in a function, subroutine or interface body.
^
ftn-1014 crayftn: ERROR Z, File = etdtp.f90, Line = 27, Column = 5
Character object "CNAME" has nonconstant bounds. It can only be declared
in a function, subroutine or interface body.
which also seems wrong.
Also, if I remove default type parmeter values in type t1:
integer, kind :: mass_kind
integer, len :: nlen, number
then compiler 1 rejects the program with:
etdtp.f90(19): error #8725: If a type parameter does not have a default
value, there must be a type parameter spec corresponding to that type
parameter. [T1]
class( t1 ) :: amph(:)
-----------^
again this seems wrong to me.
Anton
|