[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
Thu Aug 13 11:00:14 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'
 
----------------
kwyatt-ext wrote:

Verified against an unfixed build: the spurious messages for this file were expected 'COMPLEX' (double CONTAINS), expected 'INTEGER' (IMPORT), and the full type-spec avalanche including FINAL/GENERIC/PROCEDURE for the misplaced subprogram — so COMPLEX/INTEGER were real, but you're right the trailing CHECK-NOTs were vacuous. I moved them to --implicit-check-not on the RUN line so they apply to the whole output and fail as expected in the unfixed build.

https://github.com/llvm/llvm-project/pull/215886


More information about the flang-commits mailing list