Skip to content

Commit

Permalink
Fixed a type-stability issue (caused by poor constructor handling)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstjean committed Mar 26, 2018
1 parent 838b092 commit 90dce1c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/QuickTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function qexpansion(def, mutable, fully_parametric, narrow_types)
constr_args = Any[]; constr_kwargs = Any[]
o_constr_args = Any[]; o_constr_kwargs = Any[]
new_args = Symbol[]
reg_kwargs = Any[] # the passed kwargs, but without _concise_show et al.
for arg in args
if isa(arg, Expr) && arg.head==:kw # default arguments
fsym = get_sym(arg.args[1])
Expand Down Expand Up @@ -179,6 +180,7 @@ function qexpansion(def, mutable, fully_parametric, narrow_types)
concise_show = kwarg.args[2]::Bool
continue
end
push!(reg_kwargs, kwarg)
push!(kwfields, kwarg.args[1])
push!(constr_kwargs, Expr(:kw, fsym, kwarg.args[2]))
push!(new_args, fsym)
Expand All @@ -203,7 +205,7 @@ function qexpansion(def, mutable, fully_parametric, narrow_types)
return new{$(type_vars...)}($(new_args...))
end
end
straight_constr = :($name($(args...); $(kwargs...)) where {$(type_vars...)} =
straight_constr = :($name($(args...); $(reg_kwargs...)) where {$(type_vars...)} =
$name{$(given_types...)}($(o_constr_args...);
$(o_constr_kwargs...)))
type_def =
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Empty()
@qstruct Boring(x::Int)
@inferred Boring(10)
@test Boring(10).x == 10
@qstruct ParametricBoring{X}(x::X)
@qstruct ParametricBoring{X}(x::X; _concise_show=true)
@inferred ParametricBoring(10)
@test ParametricBoring(10).x === 10

Expand Down

0 comments on commit 90dce1c

Please sign in to comment.