[flang-commits] [flang] [flang] Improve error for misplaced statement after CONTAINS in derived type (PR #215886)
via flang-commits
flang-commits at lists.llvm.org
Wed Aug 12 18:06:53 PDT 2026
================
@@ -17,10 +19,35 @@ module m
! CHECK: error: component definition must precede CONTAINS in a derived type
! CHECK-NEXT: {{.*}}real, pointer, dimension(:,:,:), public :: gpoint => null()
real, pointer, dimension(:,:,:), public :: gpoint => null()
+ end type t1
+
+ ! A second CONTAINS is not a component definition.
+ type :: t2
+ contains
+ contains
+! CHECK: error: expected a type-bound procedure binding (PROCEDURE, GENERIC, or FINAL) after CONTAINS
+ end type t2
+
+ ! An IMPORT after CONTAINS is likewise not a binding.
+ type :: t3
+ contains
+ import
+! CHECK: error: expected a type-bound procedure binding (PROCEDURE, GENERIC, or FINAL) after CONTAINS
+ end type t3
+
+ ! A misplaced subprogram after CONTAINS.
+ type :: t4
+ contains
+ subroutine s
+ end subroutine
+! CHECK: error: expected a type-bound procedure binding (PROCEDURE, GENERIC, or FINAL) after CONTAINS
+ end type t4
+
! CHECK-NOT: expected 'FINAL'
! CHECK-NOT: expected 'GENERIC'
! CHECK-NOT: expected 'PROCEDURE'
- end type t1
+! CHECK-NOT: expected 'COMPLEX'
+! CHECK-NOT: expected 'INTEGER'
----------------
mleair wrote:
Were 'COMPLEX' and 'INTEGER' actually the messages emitted before this fix? intrinsicTypeSpec (R704) is a first() chain ending in DOUBLE COMPLEX/BYTE, and Flang's first() keeps the last same-depth failure message — so the pre-fix spurious message was more likely expected 'LOGICAL' or expected 'DOUBLE COMPLEX'. If so, these two CHECK-NOT lines may be passing vacuously. Could you verify by running the test against an unfixed build?
https://github.com/llvm/llvm-project/pull/215886
More information about the flang-commits
mailing list