Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Classes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ function _defclass(clsname, supercls, mutable, wheres, exprs)

# partition expressions into constructors and field defs
ctors = Vector{Expr}()
fields = Vector{Expr}()
fields = Vector{Union{Expr, Symbol}}()
for ex in exprs
try
if ex isa Symbol || (ex isa Expr && ex.head === :(::) && ex.args[1] isa Symbol ) # x or x::Int64
push!(fields, ex)
else
splitdef(ex) # throws AssertionError if not a func def
push!(ctors, ex)
catch
push!(fields, ex)
end
end

Expand Down
8 changes: 8 additions & 0 deletions test/test_classes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,11 @@ obj = AbstractLog{Float64}([1. 2.; 3. 4.])
# #= /Users/rjp/.julia/packages/MacroTools/4AjBS/src/utils.jl:302 =#
# new{T3, T4}(one, two, x, y)
# end

# x is a typeless field
@class Cat begin
x
end

@test Cat(1).x == 1
@test Cat("a").x == "a"