Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix short function constructor #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions src/compile-time.reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ function parse_class_body!(ln::LineNumberNode, self::TypeDef, body; preprocess::
continue
end

if (func_info = parse_function(ln, x, fallback = nothing, allow_lambda = false, allow_short_func = true)) isa FuncInfo
push!(self.methods, func_info)
continue
end

if (field_info = parse_field_def(ln, x, fallback = nothing)) isa FieldInfo
push!(self.fields, field_info)
continue
Expand All @@ -237,11 +242,6 @@ function parse_class_body!(ln::LineNumberNode, self::TypeDef, body; preprocess::
continue
end


if (func_info = parse_function(ln, x, fallback = nothing, allow_lambda = false, allow_short_func = false)) isa FuncInfo
push!(self.methods, func_info)
continue
end
throw(create_exception(ln, "unrecognised statement in $(self.name) definition: $(x)"))

end
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ module structdef
@test some_ref_val[] == 5
@test x.b == "sada"
end

@testset "short function constructor" begin
@oodef struct TestShortFunction
new() = begin
@mk
end
end
x = TestFunctionNew()
end
end

include("example.jl")
Expand Down