Suzhou-Tongyuan / ObjectOriented.jl

Conventional object-oriented programming in Julia without breaking Julia's core design ideas
MIT License
88 stars 6 forks source link

short function syntax #8

Open t-bltg opened 1 year ago

t-bltg commented 1 year ago

In my codes, I use the

foo() = begin
end

convention instead of

function foo()
end

As a results, this fails:

julia> using ObjectOriented
julia> @oodef struct Foo
    new() = begin
       @mk
    end
end
ERROR: LoadError: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:205
  Symbol(::Any...) at strings/basic.jl:229
Stacktrace:
 [1] ObjectOriented.CompileTime.FieldInfo(ln::Any, name::Any, type::Any, defaultVal::Any)
   @ ObjectOriented.CompileTime [...]/.julia/packages/ObjectOriented/1M2LB/src/compile-time.reflection.jl:115
 [2] ObjectOriented.CompileTime.FieldInfo(; ln::Any, name::Any, type::Any, defaultVal::Any)
   @ ObjectOriented.CompileTime util.jl:453
 [3] parse_field_def(ln::LineNumberNode, f::Any; fallback::Nothing)
   @ ObjectOriented.CompileTime [...]/.julia/packages/ObjectOriented/1M2LB/src/compile-time.reflection.jl:254
 [4] parse_class_body!(ln::LineNumberNode, self::ObjectOriented.CompileTime.TypeDef, body::Any; preprocess::ObjectOriented.CompileTime.var"#preprocess#47"{Module})
   @ ObjectOriented.CompileTime [...]/.julia/packages/ObjectOriented/1M2LB/src/compile-time.reflection.jl:230
 [5] parse_class(ln::LineNumberNode, def::Any; preprocess::ObjectOriented.CompileTime.var"#preprocess#47"{Module})
   @ ObjectOriented.CompileTime [...]/.julia/packages/ObjectOriented/1M2LB/src/compile-time.reflection.jl:170
 [6] var"@oodef"(__source__::LineNumberNode, __module__::Module, ex::Any)
   @ ObjectOriented.CompileTime [...]/.julia/packages/ObjectOriented/1M2LB/src/compile-time.jl:21
in expression starting at REPL[4]:1

We hit this pattern matching: https://github.com/Suzhou-Tongyuan/ObjectOriented.jl/blob/580c3f75051a139be4cc1af184f58ac171e17461/src/compile-time.reflection.jl#L254