[flang-commits] [flang] [flang] Reject type bound procedure overrides with mismatched passed-object dummy names (PR #210876)

via flang-commits flang-commits at lists.llvm.org
Mon Jul 20 22:10:51 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: ejose02

<details>
<summary>Changes</summary>

Fixes #<!-- -->206913

Issue:
Flang wrongly accepts a type-bound procedure override when the implementing procedure uses a different dummy name than the parent deferred interface.

Root cause:
The PASS override check uses CanOverride, which compares dummy types but not dummy names for the passed-object argument.

Fix:
Check that dummy names match before CanOverride and report a clear error

---
Full diff: https://github.com/llvm/llvm-project/pull/210876.diff


2 Files Affected:

- (modified) flang/lib/Semantics/check-declarations.cpp (+19) 
- (added) flang/test/Semantics/bindings08.f90 (+25) 


``````````diff
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 0a62e199d9779..10efb2a8ab2d6 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -2700,6 +2700,19 @@ void CheckHelper::CheckPassArg(
   }
 }
 
+static bool OverrideDummyNamesMatch(
+    const Procedure &binding, const Procedure &overridden) {
+  if (binding.dummyArguments.size() != overridden.dummyArguments.size()) {
+    return false;
+  }
+  for (std::size_t j{0}; j < binding.dummyArguments.size(); ++j) {
+    if (binding.dummyArguments[j].name != overridden.dummyArguments[j].name) {
+      return false;
+    }
+  }
+  return true;
+}
+
 void CheckHelper::CheckProcBinding(
     const Symbol &symbol, const ProcBindingDetails &binding) {
   const Scope &dtScope{symbol.owner()};
@@ -2783,6 +2796,12 @@ void CheckHelper::CheckProcBinding(
               if (*passIndex != *overriddenPassIndex) {
                 SayWithDeclaration(*overridden,
                     "A type-bound procedure and its override must use the same PASS argument"_err_en_US);
+              } else if (!OverrideDummyNamesMatch(
+                             *bindingChars, *overriddenChars)) {
+                SayWithDeclaration(*overridden,
+                    "Passed-object dummy arguments of type-bound procedure '%s' "
+                    "and its override must correspond by name and position"_err_en_US,
+                    symbol.name());
               } else if (!bindingChars->CanOverride(
                              *overriddenChars, passIndex)) {
                 SayWithDeclaration(*overridden,
diff --git a/flang/test/Semantics/bindings08.f90 b/flang/test/Semantics/bindings08.f90
new file mode 100644
index 0000000000000..4542e0091a0c9
--- /dev/null
+++ b/flang/test/Semantics/bindings08.f90
@@ -0,0 +1,25 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+module m
+    type, abstract :: parent
+        contains
+        procedure(ip), deferred :: set
+    end type
+    abstract interface
+        subroutine ip(x)
+            import parent
+            class(parent) :: x
+        end subroutine
+    end interface
+    type, public, extends(parent), abstract :: child
+    end type
+    type, extends(child) :: grandchild
+        contains
+        !ERROR: Passed-object dummy arguments of type-bound procedure 'set' and its override must correspond by name and position
+        procedure :: set
+    end type
+    contains
+    subroutine set(y)
+        class(grandchild) :: y
+    end subroutine
+end module

``````````

</details>


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


More information about the flang-commits mailing list