standard and not allowed by most other compilers.
If the `USE`-associated entity of the same name is not a procedure,
most compilers disallow it as well.
+
+* Fortran 2018 19.3.4p1: "A component name has the scope of its derived-type
+ definition. Outside the type definition, it may also appear ..." which
+ seems to imply that within its derived-type definition, a component
+ name is in its scope, and at least shadows any entity of the same name
+ in the enclosing scope and might be read, thanks to the "also", to mean
+ that a "bare" reference to the name could be used in a specification inquiry.
+ However, most other compilers do not allow a component to shadow exterior
+ symbols, much less appear in specification inquiries, and there are
+ application codes that expect exterior symbols whose names match
+ components to be visible in a derived-type definition's default initialization
+ expressions, and so f18 follows that precedent.
Symbol *ScopeHandler::FindSymbol(const Scope &scope, const parser::Name &name) {
if (scope.IsDerivedType()) {
if (Symbol * symbol{scope.FindComponent(name.source)}) {
- if (!symbol->has<ProcBindingDetails>() &&
- !symbol->has<GenericDetails>() &&
- !symbol->test(Symbol::Flag::ParentComp)) {
+ if (symbol->has<TypeParamDetails>()) {
return Resolve(name, symbol);
}
}
integer, kind :: dtypeParam = 4
type(baseType(dtypeParam)) :: baseField
!ERROR: KIND parameter value (343) of intrinsic type REAL did not resolve to a supported value
- real(baseField%baseParam) :: realField
+ real(dtypeParam) :: realField
end type dtype
type(dtype) :: v1
! RUN: %python %S/test_symbols.py %s %flang_fc1
-! "Bare" uses of type parameters and components
-
+! "Bare" uses of type parameters
!DEF: /MainProgram1/t1 DerivedType
!DEF: /MainProgram1/t1/k TypeParam INTEGER(4)
type :: t1(k)
real :: b(k)
!DEF: /MainProgram1/t2/c ObjectEntity REAL(4)
!DEF: /MainProgram1/size INTRINSIC, PURE (Function) ProcEntity
- !REF: /MainProgram1/t1/a
+ !DEF: /MainProgram1/a (Implicit) ObjectEntity REAL(4)
real :: c(size(a))
!REF: /MainProgram1/t1
!DEF: /MainProgram1/t2/x ObjectEntity TYPE(t1(k=666_4))