From 91789413234a1e358f995e3c25f989df581291a1 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 13 Jul 2021 10:29:53 +0200 Subject: [PATCH] add a test for #41096 (#41556) (cherry picked from commit d7329038feb207997b9a6d969c5c8f11d37680d5) --- test/compiler/codegen.jl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index f232b246a9fc9..cc6095b867d41 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -597,3 +597,35 @@ f41438(y) = y[].x # issue #41157 f41157(a, b) = a[1] = b[1] @test_throws BoundsError f41157(Tuple{Int}[], Tuple{Union{}}[]) + +# 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)