Skip to content

Commit

Permalink
fix precompile and more tests, from @mauro3
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Sep 24, 2018
1 parent 1a6565d commit 4891396
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 22 deletions.
50 changes: 28 additions & 22 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -697,31 +697,37 @@ end
function _kwdef!(blk, params_args, call_args)
for i in eachindex(blk.args)
ei = blk.args[i]
if isa(ei, Symbol)
if ei isa Symbol
# var
push!(params_args, ei)
push!(call_args, ei)
elseif !isa(ei, Expr)
continue
elseif ei.head == :(=)
# var::Typ = defexpr
dec = ei.args[1] # var::Typ
if isa(dec, Expr) && dec.head == :(::)
var = dec.args[1]
else
var = dec
elseif ei isa Expr
if ei.head == :(=)
lhs = ei.args[1]
if lhs isa Symbol
# var = defexpr
var = lhs
elseif lhs isa Expr && lhs.head == :(::) && lhs.args[1] isa Symbol
# var::T = defexpr
var = lhs.args[1]
else
# something else, e.g. inline inner constructor
# F(...) = ...
continue
end
defexpr = ei.args[2] # defexpr
push!(params_args, Expr(:kw, var, defexpr))
push!(call_args, var)
blk.args[i] = lhs
elseif ei.head == :(::) && ei.args[1] isa Symbol
# var::Typ
var = ei.args[1]
push!(params_args, var)
push!(call_args, var)
elseif ei.head == :block
# can arise with use of @static inside type decl
_kwdef!(ei, params_args, call_args)
end
def = ei.args[2] # defexpr
push!(params_args, Expr(:kw, var, def))
push!(call_args, var)
blk.args[i] = dec
elseif ei.head == :(::)
dec = ei # var::Typ
var = dec.args[1] # var
push!(params_args, var)
push!(call_args, var)
elseif ei.head == :block
# can arise with use of @static inside type decl
_kwdef!(ei, params_args, call_args)
end
end
blk
Expand Down
1 change: 1 addition & 0 deletions contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ function generate_precompile_statements()
# println(statement)
# Work around #28808
occursin("\"YYYY-mm-dd\\THH:MM:SS\"", statement) && continue
statement == "precompile(Tuple{typeof(Base.show), Base.IOContext{Base.TTY}, Type{Vararg{Any, N} where N}})" && continue
try
Base.include_string(PrecompileStagingArea, statement)
catch ex
Expand Down
27 changes: 27 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,33 @@ end
@test Test29307{UInt32}(a=0x03) == Test29307{UInt32}(0x03)
end

@kwdef struct TestInnerConstructor
a = 1
TestInnerConstructor(a::Int) = (@assert a>0; new(a))
function TestInnerConstructor(a::String)
@assert length(a) > 0
new(a)
end
end

@testset "@kwdef inner constructor" begin
@test TestInnerConstructor() == TestInnerConstructor(1)
@test TestInnerConstructor(a=2) == TestInnerConstructor(2)
@test_throws AssertionError TestInnerConstructor(a=0)
@test TestInnerConstructor(a="2") == TestInnerConstructor("2")
@test_throws AssertionError TestInnerConstructor(a="")
end


const outsidevar = 7
@kwdef struct TestOutsideVar
a::Int=outsidevar
end
@test TestOutsideVar() == TestOutsideVar(7)




@testset "exports of modules" begin
for (_, mod) in Base.loaded_modules
for v in names(mod)
Expand Down

0 comments on commit 4891396

Please sign in to comment.