* The character length of the `SOURCE=` or `MOLD=` in `ALLOCATE`
may be distinct from the constant character length, if any,
of an allocated object.
+* When a name is brought into a scope by multiple ways,
+ such as USE-association as well as an `IMPORT` from its host,
+ it's an error only if the resolution is ambiguous.
### Extensions supported when enabled by options
Say(std::move(*error));
}
for (auto &name : x.names) {
- if (FindSymbol(scope.parent(), name)) {
+ if (Symbol * outer{FindSymbol(scope.parent(), name)}) {
scope.add_importName(name.source);
+ if (Symbol * symbol{FindInScope(name)}) {
+ if (outer->GetUltimate() == symbol->GetUltimate()) {
+ Say(name,
+ "The same '%s' is already present in this scope"_port_en_US);
+ } else {
+ Say(name,
+ "A distinct '%s' is already present in this scope"_err_en_US)
+ .Attach(symbol->name(), "Previous declaration of '%s'"_en_US)
+ .Attach(outer->name(), "Declaration of '%s' in host scope"_en_US);
+ }
+ }
} else {
Say(name, "'%s' not found in host scope"_err_en_US);
}
--- /dev/null
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! USE vs IMPORT
+module m1
+ type t
+ integer n
+ end type
+end module
+
+module m2
+ type t
+ real x
+ end type
+end module
+
+module m3
+ use m1
+ interface
+ subroutine s1(x)
+ use m1
+ !PORTABILITY: The same 't' is already present in this scope
+ import t
+ type(t) x
+ end
+ subroutine s2(x)
+ use m2
+ !ERROR: A distinct 't' is already present in this scope
+ import t
+ type(t) x
+ end
+ end interface
+end module
+
+module m4
+ type t
+ complex z
+ end type
+ interface
+ subroutine s3(x)
+ use m1
+ !ERROR: A distinct 't' is already present in this scope
+ import t
+ type(t) x
+ end
+ end interface
+end module
+
+module m5
+ interface
+ subroutine s4(x)
+ use m1
+ !ERROR: A distinct 't' is already present in this scope
+ import t
+ type(t) x
+ end
+ end interface
+ contains
+ subroutine t
+ end
+end module