@@ -956,6 +956,17 @@ precompile_test_harness("code caching") do dir
956956 use_stale(c) = stale(c[1]) + not_stale("hello")
957957 build_stale(x) = use_stale(Any[x])
958958
959+ # bindings
960+ struct InvalidatedBinding
961+ x::Int
962+ end
963+ struct Wrapper
964+ ib::InvalidatedBinding
965+ end
966+ makewib(x) = Wrapper(InvalidatedBinding(x))
967+ const gib = makewib(1)
968+ fib() = gib.ib.x
969+
959970 # force precompilation
960971 build_stale(37)
961972 stale('c')
@@ -985,6 +996,7 @@ precompile_test_harness("code caching") do dir
985996 Base.Experimental.@force_compile
986997 useA2()
987998 end
999+ precompile($StaleA .fib, ())
9881000
9891001 ## Reporting tests
9901002 call_nbits(x::Integer) = $StaleA .nbits(x)
@@ -1014,6 +1026,15 @@ precompile_test_harness("code caching") do dir
10141026 @eval using $ StaleA
10151027 MA = invokelatest (getfield, @__MODULE__ , StaleA)
10161028 Base. eval (MA, :(nbits (:: UInt8 ) = 8 ))
1029+ Base. eval (MA, quote
1030+ struct InvalidatedBinding
1031+ x:: Float64
1032+ end
1033+ struct Wrapper
1034+ ib:: InvalidatedBinding
1035+ end
1036+ const gib = makewib (2.0 )
1037+ end )
10171038 @eval using $ StaleC
10181039 invalidations = Base. StaticData. debug_method_invalidation (true )
10191040 @eval using $ StaleB
@@ -1044,6 +1065,11 @@ precompile_test_harness("code caching") do dir
10441065 m = only (methods (MC. call_buildstale))
10451066 mi = m. specializations:: Core.MethodInstance
10461067 @test hasvalid (mi, world) # was compiled with the new method
1068+ m = only (methods (MA. fib))
1069+ mi = m. specializations:: Core.MethodInstance
1070+ @test isdefined (mi, :cache ) # it was precompiled by StaleB
1071+ @test_broken ! hasvalid (mi, world) # invalidated by redefining `gib` before loading StaleB
1072+ @test_broken MA. fib () === 2.0
10471073
10481074 # Reporting test (ensure SnoopCompile works)
10491075 @test all (i -> isassigned (invalidations, i), eachindex (invalidations))
0 commit comments