[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:04:57 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
----------------
mleair wrote:

 Does end subroutine also produce a second "expected a type-bound procedure binding" diagnostic that goes unchecked? withMessage() calls first() here — no alternative matches end, so anyTokenMatched=false and state.Say() fires the generic message. Recovery's !"END"_tok then also fails, so the message is never cleared. I think there should be a CHECK line for this.

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


More information about the flang-commits mailing list