diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index b8fa5536865bb..819ad8c67f48a 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -580,3 +580,35 @@ g40612(a, b) = a[]|a[] === b[]|b[] @test g40612(Union{Bool,Missing}[missing], Union{Bool,Missing}[missing]) @test g40612(Union{Bool,Missing}[true], Union{Bool,Missing}[true]) @test g40612(Union{Bool,Missing}[false], Union{Bool,Missing}[false]) + +# issue #41096 +struct Modulate41096{M<:Union{Function, Val{true}, Val{false}}, id} + modulate::M + Modulate41096(id::Symbol, modulate::Function) = new{typeof(modulate), id}(modulate) + Modulate41096(id::Symbol, modulate::Bool=true) = new{Val{modulate}, id}(modulate|>Val) +end +@inline ismodulatable41096(modulate::Modulate41096) = ismodulatable41096(typeof(modulate)) +@inline ismodulatable41096(::Type{<:Modulate41096{Val{B}}}) where B = B +@inline ismodulatable41096(::Type{<:Modulate41096{<:Function}}) = true + +mutable struct Term41096{I, M<:Modulate41096} + modulate::M + Term41096{I}(modulate::Modulate41096) where I = new{I, typeof(modulate)}(modulate) +end +@inline ismodulatable41096(term::Term41096) = ismodulatable41096(typeof(term)) +@inline ismodulatable41096(::Type{<:Term41096{I, M} where I}) where M = ismodulatable41096(M) + +function newexpand41096(gen, name::Symbol) + flag = ismodulatable41096(getfield(gen, name)) + if flag + return true + else + return false + end +end + +t41096 = Term41096{:t}(Modulate41096(:t, false)) +μ41096 = Term41096{:μ}(Modulate41096(:μ, false)) +U41096 = Term41096{:U}(Modulate41096(:U, false)) + +@test !newexpand41096((t=t41096, μ=μ41096, U=U41096), :U)