[flang-commits] [flang] e1ba1be - [flang] Account for accessibility in extensibility check (#128765)
via flang-commits
flang-commits at lists.llvm.org
Thu Feb 27 14:30:59 PST 2025
Author: Peter Klausler
Date: 2025-02-27T14:30:55-08:00
New Revision: e1ba1be787b845e9c174430e5005584e9d23362a
URL: https://github.com/llvm/llvm-project/commit/e1ba1be787b845e9c174430e5005584e9d23362a
DIFF: https://github.com/llvm/llvm-project/commit/e1ba1be787b845e9c174430e5005584e9d23362a.diff
LOG: [flang] Account for accessibility in extensibility check (#128765)
A derived type with a component of the same name as the type is not
extensible... unless the extension occurs in another module where the
conflicting component is inaccessible.
Fixes https://github.com/llvm/llvm-project/issues/126114.
Added:
Modified:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/resolve34.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 3fc18d1b7e219..514c0b88d350a 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7268,17 +7268,20 @@ bool DeclarationVisitor::OkToAddComponent(
std::optional<parser::MessageFixedText> msg;
std::optional<common::UsageWarning> warning;
if (context().HasError(*prev)) { // don't pile on
- } else if (extends) {
- msg = "Type cannot be extended as it has a component named"
- " '%s'"_err_en_US;
} else if (CheckAccessibleSymbol(currScope(), *prev)) {
// inaccessible component -- redeclaration is ok
- if (context().ShouldWarn(
- common::UsageWarning::RedeclaredInaccessibleComponent)) {
+ if (extends) {
+ // The parent type has a component of same name, but it remains
+ // extensible outside its module since that component is PRIVATE.
+ } else if (context().ShouldWarn(
+ common::UsageWarning::RedeclaredInaccessibleComponent)) {
msg =
"Component '%s' is inaccessibly declared in or as a parent of this derived type"_warn_en_US;
warning = common::UsageWarning::RedeclaredInaccessibleComponent;
}
+ } else if (extends) {
+ msg =
+ "Type cannot be extended as it has a component named '%s'"_err_en_US;
} else if (prev->test(Symbol::Flag::ParentComp)) {
msg =
"'%s' is a parent type of this type and so cannot be a component"_err_en_US;
diff --git a/flang/test/Semantics/resolve34.f90 b/flang/test/Semantics/resolve34.f90
index 4ddb8fd0b0eb8..39709a362b363 100644
--- a/flang/test/Semantics/resolve34.f90
+++ b/flang/test/Semantics/resolve34.f90
@@ -45,6 +45,11 @@ module m4
type, extends(t1) :: t2
end type
end
+module m4a
+ use m4
+ type, extends(t1) :: t3 ! ok, inaccessible component
+ end type
+end
module m5
type :: t1
More information about the flang-commits
mailing list