@@ -2432,6 +2432,86 @@ end
24322432 pop! (LOAD_PATH )
24332433 end
24342434
2435+ if Base. VERSION >= v " 1.12.0-DEV.2047" && do_test (" struct/const revision" )
2436+ @testset " struct/const revision" begin
2437+ testdir = newtestdir ()
2438+ dn = joinpath (testdir, " StructConst" , " src" )
2439+ mkpath (dn)
2440+ write (joinpath (dn, " StructConst.jl" ), """
2441+ module StructConst
2442+ const __hash__ = 0x71716e828e2d6093
2443+ struct Fixed
2444+ x::Int
2445+ end
2446+ Base.hash(f::Fixed, h::UInt) = hash(__hash__, hash(f.x, h))
2447+ struct Point
2448+ x::Float64
2449+ end
2450+ firstval(p::Point) = p.x
2451+ mynorm(p::Point) = sqrt(p.x^2)
2452+ end
2453+ """ )
2454+ sleep (mtimedelay)
2455+ @eval using StructConst
2456+ sleep (mtimedelay)
2457+ w1 = Base. get_world_counter ()
2458+ f = StructConst. Fixed (5 )
2459+ v1 = hash (f)
2460+ p = StructConst. Point (5.0 )
2461+ @test StructConst. firstval (p) == 5.0
2462+ @test StructConst. mynorm (p) == 5.0
2463+ write (joinpath (dn, " StructConst.jl" ), """
2464+ module StructConst
2465+ const __hash__ = 0xddaab158621d200c
2466+ struct Fixed
2467+ x::Int
2468+ end
2469+ Base.hash(f::Fixed, h::UInt) = hash(__hash__, hash(f.x, h))
2470+ struct Point
2471+ x::Float64
2472+ y::Float64
2473+ end
2474+ firstval(p::Point) = p.x
2475+ mynorm(p::Point) = sqrt(p.x^2 + p.y^2)
2476+ end
2477+ """ )
2478+ @yry ()
2479+ @test StructConst. __hash__ == 0xddaab158621d200c
2480+ v2 = hash (f)
2481+ @test v1 != v2
2482+ # Call with old objects
2483+ @test StructConst. firstval (p) == 5.0 # was not redefined, so still valid
2484+ @test_throws MethodError StructConst. mynorm (p) # was redefined, so invalid
2485+ @test Base. invoke_in_world (w1, StructConst. mynorm, p) == 5.0 # but we can still call it in an old world
2486+ # Call with new objects
2487+ p2 = StructConst. Point (3.0 , 4.0 )
2488+ @test @eval (StructConst. firstval ($ p2)) == 3.0
2489+ @test @eval (StructConst. mynorm ($ p2)) == 5.0
2490+ write (joinpath (dn, " StructConst.jl" ), """
2491+ module StructConst
2492+ const __hash__ = 0x71716e828e2d6093
2493+ struct Fixed
2494+ x::Int
2495+ end
2496+ Base.hash(f::Fixed, h::UInt) = hash(__hash__, hash(f.x, h))
2497+ struct Point
2498+ x::Float64
2499+ y::Float64
2500+ end
2501+ firstval(p::Point) = p.x
2502+ mynorm(p::Point) = sqrt(p.x^2 + p.y^2)
2503+ end
2504+ """ )
2505+ @yry ()
2506+ @test StructConst. __hash__ == 0x71716e828e2d6093
2507+ v3 = hash (f)
2508+ @test v1 == v3
2509+
2510+ rm_precompile (" StructConst" )
2511+ pop! (LOAD_PATH )
2512+ end
2513+ end
2514+
24352515 do_test (" get_def" ) && @testset " get_def" begin
24362516 testdir = newtestdir ()
24372517 dn = joinpath (testdir, " GetDef" , " src" )
0 commit comments