From 3eefc470890c88c79d7c4b13ba81c7fa0720d2b8 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Mon, 8 May 2023 17:14:17 +0200 Subject: [PATCH] fix short function constructor --- src/compile-time.reflection.jl | 10 +++++----- test/runtests.jl | 9 +++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/compile-time.reflection.jl b/src/compile-time.reflection.jl index b743546..adddccf 100644 --- a/src/compile-time.reflection.jl +++ b/src/compile-time.reflection.jl @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 61f2155..458dbfa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")