我要评分
获取效率
正确性
完整性
易理解

Polymorphisms of Parameterized Derived Extension Types Are Not Recommended

Polymorphisms of parameterized derived extension types are not recommended. They may cause problems in some cases.

For example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
module test
    implicit none
    type :: ty(a, b)
        integer, len :: a, b
        real(4) :: r1(b)
    end type
    type, extends (ty) :: ty1(c)
        Integer, len :: c
        real(4) :: r2(c)
    end type
end module
 
program main
    use test
    implicit none
    type (ty1(:, :, :)), allocatable :: x
    allocate (ty1(3, 2, 20) :: x)
    x%r1 = 1.0
    x%r2 = 2.0
end program