File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -613,6 +613,21 @@ end module
613
613
associated objects and do not elicit errors about improper redeclarations
614
614
of implicitly typed entities.
615
615
616
+ * Standard Fortran allows forward references to derived types, which
617
+ can lead to ambiguity when combined with host association.
618
+ Some Fortran compilers resolve the type name to the host type,
619
+ others to the forward-referenced local type; this compiler diagnoses
620
+ an error.
621
+ ```
622
+ module m
623
+ type ambiguous; integer n; end type
624
+ contains
625
+ subroutine s
626
+ type(ambiguous), pointer :: ptr
627
+ type ambiguous; real a; end type
628
+ end
629
+ end
630
+ ```
616
631
617
632
## De Facto Standard Features
618
633
Original file line number Diff line number Diff line change @@ -6429,6 +6429,11 @@ std::optional<DerivedTypeSpec> DeclarationVisitor::ResolveDerivedType(
6429
6429
Say (name, " Derived type '%s' not found" _err_en_US);
6430
6430
return std::nullopt;
6431
6431
}
6432
+ } else if (&DEREF (symbol).owner () != &outer &&
6433
+ !ultimate->has <GenericDetails>()) {
6434
+ // Prevent a later declaration in this scope of a host-associated
6435
+ // type name.
6436
+ outer.add_importName (name.source );
6432
6437
}
6433
6438
if (CheckUseError (name)) {
6434
6439
return std::nullopt;
@@ -8096,7 +8101,7 @@ void ResolveNamesVisitor::CheckImport(
8096
8101
const Symbol &ultimate{symbol->GetUltimate ()};
8097
8102
if (&ultimate.owner () == &currScope ()) {
8098
8103
Say (location, " '%s' from host is not accessible" _err_en_US, name)
8099
- .Attach (symbol->name (), " '%s' is hidden by this entity" _en_US ,
8104
+ .Attach (symbol->name (), " '%s' is hidden by this entity" _because_en_US ,
8100
8105
symbol->name ());
8101
8106
}
8102
8107
}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ subroutine s1(x)
9
9
! ERROR: 't1' from host is not accessible
10
10
import :: t1
11
11
type (t1) :: x
12
+ ! BECAUSE: 't1' is hidden by this entity
12
13
integer :: t1
13
14
end subroutine
14
15
subroutine s2 ()
@@ -24,6 +25,7 @@ subroutine s4(x, y)
24
25
import, all
25
26
type (t1) :: x
26
27
type (t3) :: y
28
+ ! BECAUSE: 't3' is hidden by this entity
27
29
integer :: t3
28
30
end subroutine
29
31
end interface
@@ -41,6 +43,27 @@ subroutine s7()
41
43
! ERROR: 's5' is an external procedure without the EXTERNAL attribute in a scope with IMPLICIT NONE(EXTERNAL)
42
44
call s5()
43
45
end
46
+ subroutine s8 ()
47
+ ! This case is a dangerous ambiguity allowed by the standard.
48
+ ! ERROR: 't1' from host is not accessible
49
+ type (t1), pointer :: p
50
+ ! BECAUSE: 't1' is hidden by this entity
51
+ type t1
52
+ integer n(2 )
53
+ end type
54
+ end
55
+ subroutine s9 ()
56
+ ! This case is a dangerous ambiguity allowed by the standard.
57
+ type t2
58
+ ! ERROR: 't1' from host is not accessible
59
+ type (t1), pointer :: p
60
+ end type
61
+ ! BECAUSE: 't1' is hidden by this entity
62
+ type t1
63
+ integer n(2 )
64
+ end type
65
+ type (t2) x
66
+ end
44
67
end module
45
68
module m2
46
69
integer , parameter :: ck = kind (' a' )
You can’t perform that action at this time.
0 commit comments