mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 03:26:48 +00:00

Ensure that type parameters are declared as such before being referenced within the derived type definition. (Previously, such references would resolve to symbols in the enclosing scope.) This change causes the symbols for the type parameters to be created when the TYPE statement is processed in name resolution. They are TypeParamDetails symbols with no KIND/LEN attribute set, and they shadow any symbols of the same name in the enclosing scope. When the type parameter declarations are processed, the KIND/LEN attributes are set. Any earlier reference to a type parameter with no KIND/LEN attribute elicits an error. Some members of TypeParamDetails have been retyped &/or renamed.
54 lines
1.8 KiB
Fortran
54 lines
1.8 KiB
Fortran
! RUN: %python %S/test_errors.py %s %flang_fc1
|
|
! Derived type parameters
|
|
! C731 The same type-param-name shall not appear more than once in a given
|
|
! derived-type-stmt.
|
|
! C741 A type-param-name in a type-param-def-stmt in a derived-type-def shall
|
|
! be one of the type-paramnames in the derived-type-stmt of that
|
|
! derived-type-def.
|
|
! C742 Each type-param-name in the derived-type-stmt in a derived-type-def
|
|
! shall appear exactly once as a type-param-name in a type-param-def-stmt
|
|
! in that derived-type-def.
|
|
|
|
module m
|
|
!ERROR: Type parameter, component, or procedure binding 'a' already defined in this type
|
|
type t1(a, b, a)
|
|
integer, kind :: a
|
|
integer(8), len :: b
|
|
end type
|
|
!ERROR: No definition found for type parameter 'b'
|
|
type t2(a, b, c)
|
|
integer, kind :: a
|
|
integer, len :: c
|
|
end type
|
|
!ERROR: No definition found for type parameter 'b'
|
|
type t3(a, b)
|
|
integer, kind :: a
|
|
!ERROR: Component 'b' is already declared in this derived type
|
|
integer :: b
|
|
end type
|
|
type t4(a)
|
|
integer, kind :: a
|
|
!ERROR: 'd' is not a parameter of this derived type
|
|
integer(8), len :: d
|
|
end type
|
|
type t5(a, b)
|
|
integer, len :: a
|
|
integer, len :: b
|
|
!ERROR: Type parameter 'a' was already declared in this derived type
|
|
integer, len :: a
|
|
end type
|
|
!ERROR: No definition found for type parameter 'k'
|
|
!ERROR: No definition found for type parameter 'l'
|
|
type :: t6(k, l)
|
|
!ERROR: Type parameter 'k' was referenced before being declared
|
|
!ERROR: Type parameter 'l' was referenced before being declared
|
|
character(kind=k, len=l) :: d3
|
|
end type
|
|
type(t6(2, 10)) :: x3
|
|
type :: t7(k1,k2)
|
|
!ERROR: Type parameter 'k2' was referenced before being declared
|
|
integer(kind(k2)), kind :: k1
|
|
integer(kind(k1)), kind :: k2
|
|
end type
|
|
end module
|