From 90dce1c911b32ffb1a5da5110901e5141351db36 Mon Sep 17 00:00:00 2001 From: Cedric St-Jean Date: Sun, 25 Mar 2018 21:28:18 -0400 Subject: [PATCH] Fixed a type-stability issue (caused by poor constructor handling) --- src/QuickTypes.jl | 4 +++- test/runtests.jl | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/QuickTypes.jl b/src/QuickTypes.jl index 754312c..15e068d 100644 --- a/src/QuickTypes.jl +++ b/src/QuickTypes.jl @@ -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]) @@ -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) @@ -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 = diff --git a/test/runtests.jl b/test/runtests.jl index 4e946cc..21d47be 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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