Skip to content

Commit

Permalink
Merge pull request #12 from jw3126/issue11
Browse files Browse the repository at this point in the history
fix unassigned keywords (#11)
  • Loading branch information
cstjean authored Dec 27, 2018
2 parents 314df81 + 1fde45e commit 088ae82
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ os:
- linux
- osx
julia:
- 0.6
- '0.7'
- '1.0'
- nightly
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
julia 0.7-
MacroTools 0.3.2
Compat 0.15.0
14 changes: 4 additions & 10 deletions src/QuickTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ module QuickTypes
using MacroTools: @capture, prewalk, @match, splitarg
import Compat

export @qmutable, @qstruct # Julia 0.6
export @qtype, @qimmutable # Julia 0.5
export @qmutable_fp, @qstruct_fp # Julia 0.6
export @qmutable, @qstruct
export @qmutable_fp, @qstruct_fp
export @qstruct_np, @qmutable_np

const special_kwargs = [:_define_show, :_concise_show]
Expand Down Expand Up @@ -203,7 +202,8 @@ function qexpansion(def, mutable, fully_parametric, narrow_types)
push!(constr_kwargs, kwarg)
else
push!(new_args, arg_name)
push!(constr_kwargs, Expr(:kw, arg_name, default))
push!(constr_kwargs,
default === nothing ? arg_name : Expr(:kw, arg_name, default))
end
push!(reg_kwargs, kwarg)
push!(kwfields, :($arg_name::$arg_type))
Expand Down Expand Up @@ -284,17 +284,11 @@ unless `_define_show=false` (eg. `@qstruct(x, y; _define_show=false)`).
macro qstruct(def)
return qexpansion(def, false, false, false)
end
macro qimmutable(def) # 0.5 and below
return qexpansion(def, false, false, false)
end

""" Quick mutable struct definition. See ?@qstruct """
macro qmutable(def)
return qexpansion(def, true, false, false)
end
macro qtype(def) # 0.5 and below
return qexpansion(def, true, false, false)
end

# -----------------------------------------------------------------------------
# Fully-parametric
Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ c = Car(10; manufacturer=("Danone", "Hershey"))
# Check that the fields are in the right order
@test collect(fieldnames(Car)) == [:size, :nwheels, :manufacturer, :brand]
# This is essentially the definition of these functions.
# This works in Julia 0.6, but not in 0.5. Since it's not part of the exported API,
# we diable the test.
# @test construct(roottypeof(c), fieldsof(c)...) == c
@test construct(roottypeof(c), fieldsof(c)...) == c
@test type_parameters(Vector{Int}) == Base.Core.svec(Int64, 1)
@test tuple_parameters(Tuple{Int, Float64}) == Base.Core.svec(Int64, Float64)
@inferred roottypeof(1=>2) == Pair
Expand Down Expand Up @@ -91,3 +89,5 @@ convert_f(foo) = convert(foo.a, 10)
@inferred convert_f(Foo_np(Int, 2))
@test fieldtype(typeof(Foo_np(Int, 2)), :a) == Type{Int64}

@qstruct Issue11(;no_default_value)
@test_throws UndefKeywordError Issue11()

0 comments on commit 088ae82

Please sign in to comment.