Skip to content

Commit

Permalink
Add ismutabletype
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro3 committed Oct 3, 2021
1 parent fe75815 commit 514f7e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,16 @@ if VERSION < v"1.7.0-DEV.793"
end
end

if !isdefined(Base, Symbol("ismutabletype"))
# Borrowed from julia base
export ismutabletype
function ismutabletype(@nospecialize(t::Type))
t = Base.unwrap_unionall(t)
# TODO: what to do for `Union`?
return isa(t, DataType) && t.mutable
end
end

# https://github.com/JuliaLang/julia/pull/42125
if !isdefined(Base, Symbol("@constprop"))
if isdefined(Base, Symbol("@aggressive_constprop"))
Expand Down
9 changes: 7 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ end
# Check that the ExceptionStacks contain the expected last exception type:
@test typeof.(first.(excs_with_bts)) == [DivideError]
@test typeof.(first.(excs_sans_bts)) == [DivideError]

# Check that the ExceptionStack with backtraces `show`s correctly:
@test occursin(r"""
1-element ExceptionStack:
Expand Down Expand Up @@ -1277,7 +1277,7 @@ end
return sum(sincos(a))
end
end

@test foo1(42) == foo2(42)
end

Expand All @@ -1293,3 +1293,8 @@ end
@test_throws MethodError convert(Period, Minute(1) + Second(30))
@test_throws MethodError convert(Dates.FixedPeriod, Minute(1) + Second(30))
end

@testset "ismutabletype" begin
@test ismutabletype(Array)
@test !ismutabletype(Tuple)
end

0 comments on commit 514f7e9

Please sign in to comment.