Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Associate Construct

New Contributor I

I see that for the program below, 2018 update 1 gives a compile time error. (compilers until 2017 update 4 didn't do so. Haven't tested it with update 5 and 6.) Just checking if it indeed "as per standard".



      Program Test
         Implicit None
         Type newOBJ
            Integer :: I
         End Type newOBJ
         Type(newOBJ) :: OBJ
         Associate(This => OBJ, I => This%I) ! Use of "This" is not allowed? Is that correct?
               I = 1
         End Associate
         ! The lines below would be what is needed
         !Associate(This => OBJ)
         !   Associate(I => This%I)  ! Breaking it into two separate associates is allowed; other option would be to use OBJ%I
         !      I = 1
         !   End Associate
         !End Associate
      End Program Test

0 Kudos
1 Reply

Yes, this is intended, per naming scoping rules.

The associate-name has the scope of the block of the ASSOCIATE construct, and so doesn't become "live" until inside the ASSOCIATE itself. 

Your nested ASSOCIATE would be the correct solution ( or, to use OBJ%I, as you stated, too )


PS: You won't see this message in a 17.x compiler; the fix only went into 18.0 and later.