brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · 7df6cfc Raw
91 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Error tests for structure constructors.3! Errors caught by name resolution are tested elsewhere; these are the4! errors meant to be caught by expression semantic analysis, as well as5! acceptable use cases.6! Type parameters are used here to make the parses unambiguous.7! C796 (R756) The derived-type-spec shall not specify an abstract type (7.5.7).8!   This refers to a derived-type-spec used in a structure constructor9 10module module111  type :: type1(j)12    integer, kind :: j13    integer :: n = 114  end type type115  type, extends(type1) :: type2(k)16    integer, kind :: k17    integer :: m18  end type type219  type, abstract :: abstract(j)20    integer, kind :: j21    integer :: n22  end type abstract23  type :: privaten(j)24    integer, kind :: j25    integer, private :: n26  end type privaten27 contains28  subroutine type1arg(x)29    type(type1(0)), intent(in) :: x30  end subroutine type1arg31  subroutine type2arg(x)32    type(type2(0,0)), intent(in) :: x33  end subroutine type2arg34  subroutine abstractarg(x)35    class(abstract(0)), intent(in) :: x36  end subroutine abstractarg37  subroutine errors38    call type1arg(type1(0)())39    call type1arg(type1(0)(1))40    call type1arg(type1(0)(n=1))41    !ERROR: Type parameter 'j' may not appear as a component of a structure constructor42    call type1arg(type1(0)(j=1))43    !ERROR: Component 'n' conflicts with another component earlier in this structure constructor44    call type1arg(type1(0)(1,n=2))45    !ERROR: Value in structure constructor lacks a component name46    call type1arg(type1(0)(n=1,2))47    !ERROR: Component 'n' conflicts with another component earlier in this structure constructor48    call type1arg(type1(0)(n=1,n=2))49    !ERROR: Unexpected value in structure constructor50    call type1arg(type1(0)(1,2))51    call type2arg(type2(0,0)(n=1,m=2))52    call type2arg(type2(0,0)(m=2))53    !ERROR: Structure constructor lacks a value for component 'm'54    call type2arg(type2(0,0)())55    call type2arg(type2(0,0)(type1=type1(0)(n=1),m=2))56    call type2arg(type2(0,0)(type1=type1(0)(),m=2))57    !ERROR: Component 'type1' conflicts with another component earlier in this structure constructor58    call type2arg(type2(0,0)(n=1,type1=type1(0)(n=2),m=3))59    !ERROR: Component 'n' conflicts with another component earlier in this structure constructor60    call type2arg(type2(0,0)(type1=type1(0)(n=1),n=2,m=3))61    !ERROR: Component 'n' conflicts with another component earlier in this structure constructor62    call type2arg(type2(0,0)(type1=type1(0)(1),n=2,m=3))63    !ERROR: Type parameter 'j' may not appear as a component of a structure constructor64    call type2arg(type2(0,0)(j=1, &65    !ERROR: Type parameter 'k' may not appear as a component of a structure constructor66      k=2,m=3))67    !ERROR: ABSTRACT derived type 'abstract' may not be used in a structure constructor68    call abstractarg(abstract(0)(n=1))69    !This case is ok70  end subroutine errors71  subroutine polycomponent72    type :: poly73      class(*), allocatable :: p74    end type poly75    type(poly) :: x76    type :: poly277      class(type1(1)), allocatable :: p178      type(type1(1)), allocatable :: p279    end type poly280    type(type1(1)) :: t1val81    type(poly2) :: x282    ! These cases are not errors83    x = poly(1)84    x = poly('hello')85    x = poly(type1(1)(123))86    x2 = poly2(t1val, t1val)87    !ERROR: Value in structure constructor is incompatible with component 'p' of type CLASS(*)88    x = poly(z'feedface')89  end subroutine90end module module191