1! RUN: %python %S/test_errors.py %s %flang_fc1 2! Test USE statements that use same module multiple times mixed with rename 3! clauses and ONLY clauses 4module m1 5 integer :: a = 1 6 integer :: b = 2 7end module m1 8module m2 9 integer :: a = 3 10end module m2 11module m3 12 integer :: a = 1 13 type t1 14 real t1_value 15 end type 16 type t2 17 complex t2_value 18 end type 19end module m3 20module m4 21 use m1 22end module m4 23module m5 24 use m1 25 use m1, z=>a 26end module m5 27module m6 28 use m1, only : a 29end module m6 30program testUse1 31 use m1 32 use m1,z=>a ! This prevents the use association of m1's "a" as local "a" 33 use m2 ! m2's version of "a" gets use associated 34 !ERROR: 'a' is use-associated from module 'm2' and cannot be re-declared 35 integer :: a = 2 36end 37subroutine testUse2 38 use m1,only : a ! This forces the use association of m1's "a" as local "a" 39 use m1,z=>a ! This rename doesn't affect the previous forced USE association 40 !ERROR: 'a' is use-associated from module 'm1' and cannot be re-declared 41 integer :: a = 2 42end 43subroutine testUse3 44 use m1 ! By itself, this would use associate m1's "a" with a local "a" 45 use m1,z=>a ! This rename of m1'a "a" removes the previous use association 46 integer :: a = 2 47end 48subroutine testUse4 49 use m1,only : a ! Use associate m1's "a" with local "a" 50 use m1,z=>a ! Also use associate m1's "a" with local "z", also pulls in "b" 51 !ERROR: 'b' is use-associated from module 'm1' and cannot be re-declared 52 integer :: b = 2 53end 54subroutine testUse5 55 use m1,z=>a ! The rename prevents creation of a local "a" 56 use m1 ! Does not create a local "a" because of the previous rename 57 integer :: a = 2 58end 59subroutine testUse6 60 use m1, z => a ! Hides m1's "a" 61 use m1, y => b ! Hides m1's "b" 62 integer :: a = 4 ! OK 63 integer :: b = 5 ! OK 64end 65subroutine testUse7 66 use m3,t1=>t2,t2=>t1 ! Looks weird but all is good 67 type(t1) x 68 type(t2) y 69 x%t2_value = a 70 y%t1_value = z 71end 72subroutine testUse8 73 use m4 ! This USE associates all of m1 74 !ERROR: 'a' is use-associated from module 'm4' and cannot be re-declared 75 integer :: a = 2 76end 77subroutine testUse9 78 use m5 79 integer :: a = 2 80end 81subroutine testUse10 82 use m4 83 use m4, z=>a ! This rename erases the USE assocated "a" from m1 84 integer :: a = 2 85end 86subroutine testUse11 87 use m6 88 use m6, z=>a ! This rename erases the USE assocated "a" from m1 89 integer :: a = 2 90end 91subroutine testUse12 92 use m4 ! This USE associates "a" from m1 93 use m1, z=>a ! This renames the "a" from m1, but not the one through m4 94 !ERROR: 'a' is use-associated from module 'm4' and cannot be re-declared 95 integer :: a = 2 96end 97subroutine testUse13 98 use m1, a => a 99 use m1, z => a ! should not erase 'a', it was renamed 100 !ERROR: 'a' is use-associated from module 'm1' and cannot be re-declared 101 integer :: a = 13 102end 103