Skip to content

Commit 40ed6ba

Browse files
authored
[flang][NFC] Document an intentional violation of the standard (#99073)
The Fortran standard committees passed an "interp" request at their June 2024 meetings that is distinct from nearly every other Fortran compiler that I tried (6) in an an ambiguous case (parent component naming when the base type has been renamed via USE association). Document this case in flang/docs/Extensions.md as an intentional instance of non-conformance chosen for portability and better usability.
1 parent 0004ca6 commit 40ed6ba

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

flang/docs/Extensions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ end
134134
implicitly simply appearing in an asynchronous data transfer statement,
135135
without the attribute being visible in the procedure's explicit
136136
interface.
137+
* When the name of an extended derived type's base type is the
138+
result of `USE` association with renaming, the name of the extended
139+
derived type's parent component is the new name by which the base
140+
is known in the scope of the extended derived type, not the original.
141+
This interpretation has usability advantages and is what six other
142+
Fortran compilers do, but is not conforming now that J3 approved an
143+
"interp" in June 2024 to the contrary.
137144

138145
## Extensions, deletions, and legacy features supported by default
139146

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
! Every other Fortran compiler (but one) interprets the names of parent
3+
! components like this when the names of their types are the product of
4+
! USE association with renaming.
5+
6+
module m1
7+
type originalName
8+
integer m
9+
end type
10+
end
11+
12+
module m2
13+
use m1, newName => originalName
14+
type, extends(newName) :: extended
15+
integer n
16+
end type
17+
type, extends(newName) :: extended2
18+
integer originalName ! ok
19+
end type
20+
contains
21+
subroutine s1
22+
type(extended) x
23+
type(extended2) x2
24+
print *, x%newName%m ! ok
25+
!ERROR: Component 'originalname' not found in derived type 'extended'
26+
print *, x%originalName
27+
print *, extended(newName=newName(m=1),n=2) ! ok
28+
!ERROR: Structure constructor lacks a value for component 'm'
29+
!ERROR: Keyword 'originalname=' does not name a component of derived type 'extended'
30+
!ERROR: Keyword 'm=' may not appear in a reference to a procedure with an implicit interface
31+
print *, extended(originalName=originalName(m=1),n=2)
32+
!ERROR: Value in structure constructor of type 'REAL(4)' is incompatible with component 'newname' of type 'newname'
33+
!ERROR: Keyword 'm=' may not appear in a reference to a procedure with an implicit interface
34+
print *, extended(newName=originalName(m=1),n=2)
35+
!ERROR: Structure constructor lacks a value for component 'm'
36+
!ERROR: Keyword 'originalname=' does not name a component of derived type 'extended'
37+
print *, extended(originalName=newName(m=1),n=2)
38+
print *, x2%newName%m ! ok
39+
print *, x2%originalName ! ok
40+
print *, extended2(newName=newName(m=1),originalName=2) ! ok
41+
end
42+
end
43+
44+
module m3
45+
use m2
46+
contains
47+
! Same as above, but not in the same module as the derived
48+
! types' definitions.
49+
subroutine s2
50+
type(extended) x
51+
type(extended2) x2
52+
print *, x%newName%m ! ok
53+
!ERROR: Component 'originalname' not found in derived type 'extended'
54+
print *, x%originalName
55+
print *, extended(newName=newName(m=1),n=2) ! ok
56+
!ERROR: Structure constructor lacks a value for component 'm'
57+
!ERROR: Keyword 'originalname=' does not name a component of derived type 'extended'
58+
!ERROR: Keyword 'm=' may not appear in a reference to a procedure with an implicit interface
59+
print *, extended(originalName=originalName(m=1),n=2)
60+
!ERROR: Value in structure constructor of type 'REAL(4)' is incompatible with component 'newname' of type 'newname'
61+
!ERROR: Keyword 'm=' may not appear in a reference to a procedure with an implicit interface
62+
print *, extended(newName=originalName(m=1),n=2)
63+
!ERROR: Structure constructor lacks a value for component 'm'
64+
!ERROR: Keyword 'originalname=' does not name a component of derived type 'extended'
65+
print *, extended(originalName=newName(m=1),n=2)
66+
print *, x2%newName%m ! ok
67+
print *, x2%originalName ! ok
68+
print *, extended2(newName=newName(m=1),originalName=2) ! ok
69+
end
70+
end

0 commit comments

Comments
 (0)