Fortran · 940 bytes Raw Blame History
1 ! Audit #4 CRITICAL-4 — contained subprograms inherit host USE
2 ! imports via host association.
3 !
4 ! Fixed: lower_unit now takes a `host_uses` slice. Each call
5 ! computes a `combined_uses = host_uses ++ self_uses` and passes
6 ! the combined list both to install_globals_as_locals AND to any
7 ! nested contains recursion. Per F2018 §16.2, host association
8 ! makes parent USE imports visible inside contained subprograms.
9 !
10 ! While here, also fixed the latent bug that Subroutine/Function
11 ! arms didn't recurse into their own `contains` at all — only
12 ! Program did. fortsh has nested-subprogram chains where this
13 ! would have silently dropped the inner subs.
14 !
15 ! CHECK: 42
16 program audit4_c4_host_association
17 use audit4_c4_mod
18 call inner()
19 contains
20 subroutine inner()
21 print *, v ! host association — should resolve to mod_v.v == 42
22 end subroutine
23 end program
24
25 module audit4_c4_mod
26 integer :: v = 42
27 end module audit4_c4_mod
28