[flang-commits] [PATCH] D145109: [flang] Catch name conflict between generic TBP and inherited non-generic

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Mar 2 10:20:27 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2216c4c6a4e2: [flang] Catch name conflict between generic TBP and inherited non-generic (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145109/new/

https://reviews.llvm.org/D145109

Files:
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/resolve117.f90


Index: flang/test/Semantics/resolve117.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/resolve117.f90
@@ -0,0 +1,27 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Test name conflicts with type-bound generics
+module m
+  type base1(k)
+    integer, kind :: k = 4
+    real x
+   contains
+    procedure, nopass :: tbp => sub
+    generic :: gen => tbp
+  end type
+  type, extends(base1) :: ext1
+   contains
+    procedure, nopass :: sub
+    !ERROR: Type parameter, component, or procedure binding 'base1' already defined in this type
+    generic :: base1 => sub
+    !ERROR: Type bound generic procedure 'k' may not have the same name as a non-generic symbol inherited from an ancestor type
+    generic :: k => sub
+    !ERROR: Type bound generic procedure 'x' may not have the same name as a non-generic symbol inherited from an ancestor type
+    generic :: x => sub
+    !ERROR: Type bound generic procedure 'tbp' may not have the same name as a non-generic symbol inherited from an ancestor type
+    generic :: tbp => sub
+    generic :: gen => sub ! ok
+  end type
+ contains
+  subroutine sub
+  end
+end
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -5226,7 +5226,7 @@
   const auto &accessSpec{std::get<std::optional<parser::AccessSpec>>(x.t)};
   const auto &genericSpec{std::get<Indirection<parser::GenericSpec>>(x.t)};
   const auto &bindingNames{std::get<std::list<parser::Name>>(x.t)};
-  auto info{GenericSpecInfo{genericSpec.value()}};
+  GenericSpecInfo info{genericSpec.value()};
   SourceName symbolName{info.symbolName()};
   bool isPrivate{accessSpec ? accessSpec->v == parser::AccessSpec::Kind::Private
                             : derivedTypeInfo_.privateBindings};
@@ -5236,17 +5236,19 @@
       genericSymbol = nullptr; // MakeTypeSymbol will report the error below
     }
   } else {
-    // look in parent types:
-    Symbol *inheritedSymbol{nullptr};
+    // look in ancestor types for a generic of the same name
     for (const auto &name : GetAllNames(context(), symbolName)) {
-      inheritedSymbol = currScope().FindComponent(SourceName{name});
-      if (inheritedSymbol) {
+      if (Symbol * inherited{currScope().FindComponent(SourceName{name})}) {
+        if (inherited->has<GenericDetails>()) {
+          CheckAccessibility(symbolName, isPrivate, *inherited); // C771
+        } else {
+          Say(symbolName,
+              "Type bound generic procedure '%s' may not have the same name as a non-generic symbol inherited from an ancestor type"_err_en_US)
+              .Attach(inherited->name(), "Inherited symbol"_en_US);
+        }
         break;
       }
     }
-    if (inheritedSymbol && inheritedSymbol->has<GenericDetails>()) {
-      CheckAccessibility(symbolName, isPrivate, *inheritedSymbol); // C771
-    }
   }
   if (genericSymbol) {
     CheckAccessibility(symbolName, isPrivate, *genericSymbol); // C771


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145109.501914.patch
Type: text/x-patch
Size: 3096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230302/1dd9fbdf/attachment.bin>


More information about the flang-commits mailing list