Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29487 Discussions

Possible compiler bug, Versions 12.0.2.154, 12.0.3.174

mecej4
Honored Contributor III
610 Views
This example, adapted from the one in a recent thread ("Interface of an internal module function as class constructor"), exhibits what to me seems to be a bug in the compiler (12.0.2 - Windows, 12.0.3 - Linux). It is remarkable that the compiler reports no errors and the resulting program, when run, displays results that agree with what a programmer may have intended it to do! The program was obtained by removing polymorphic types from the referenced post.

[fortran]module shape_mod
implicit none
private ! hide the type-bound procedure implementation procedures
public :: shapex, sprint

type shapex
private ! hide the underlying details
integer :: color
logical :: filled
integer :: x
integer :: y
end type shapex

interface shapex !BUG: is "shapex" type-name or procedure-name?
module procedure constructor
end interface

contains

function constructor(color, filled, x, y)
implicit none
type(shapex) :: constructor
integer :: color
logical :: filled
integer :: x
integer :: y
call initShape(constructor,color, filled, x, y)
end function constructor

subroutine initShape(shpe, color, filled, x, y)
! initialize shape objects
implicit none
type(shapex) :: shpe
integer :: color
logical :: filled
integer :: x
integer :: y

shpe%color = color
shpe%filled = filled
shpe%x = -x
shpe%y = -y
end subroutine initShape

subroutine sprint(shpe)
implicit none
type(shapex) :: shpe
print *, shpe%color, shpe%filled, shpe%x, shpe%y
end subroutine sprint

end module

program shape_prg
use shape_mod
implicit none
type(shapex) :: sh
sh = shapex(5, .true., 100, 200) ! BUG: is RHS a derived type constant or a type-bound-procedure call?
call sprint(sh)
end

[/fortran]
The program is in error because shapex is used as the name of a derived type as well as the name of a module procedure. As a consequence, the assignment statement in the main program (3rd line from the end) is ambiguous.

If the module procedure name is changed, say to shapey, the assignment statement would be still in error, since it tries to access private components of the derived type.

Other compilers flag the program with syntax errors. For example, the Sun Linux compiler version 8.5 says:

"shape.f90", Line = 14, Column = 15: ERROR: "SHAPEX" is a type-name, therefore it must not be declared as a generic-name.

but that compiler does not claim to be an F2003 compiler.
0 Kudos
2 Replies
Steven_L_Intel1
Employee
610 Views
The Sun Linux compiler is wrong. The code is legal in F2003. I quoted from the standard in the other topic.
0 Kudos
mecej4
Honored Contributor III
610 Views
Thanks, Steve. The corresponding section numbers in the Fortran 2003 standard are slightly different: 16.2, 12.3.2.1 and 4.5.9.
0 Kudos
Reply