aminya / AcuteML.jl

Acute Markup Language - HTML/XML in Julia
https://aminya.github.io/AcuteML.jl/dev
MIT License
6 stars 4 forks source link

Extractor: ERROR: MethodError: Cannot `convert` an object of type Nothing to an object of type Array{ #142

Closed szafna closed 3 years ago

szafna commented 4 years ago

Hi, I have this simple MWE:

using AcuteML

@aml mutable struct inner "~"
    id1::Int, att"~"
    desc1::String, "~"
end
@aml mutable struct outer doc"outer"
    id2::Int, att"~"
    innerList::Vector{inner}, "~"
end
i1=inner(id1=1, desc1="desc1")
i2=inner(id1=2, desc1="desc2")
o1=outer(id2=3, innerList=[i1, i2])
pprint(o1)

pprint("c:/tmp/o1.xml",o1)

Written xml file looks correct. However extracting results in error:

xml=parsexml(read("c:/tmp/o1.xml"))

o2=outer(xml)

ERROR: MethodError: Cannot `convert` an object of type Nothing to an object of type Array{inner,1}
Closest candidates are:
  convert(::Type{T}, ::AbstractArray) where T<:Array at array.jl:554
  convert(::Type{T}, ::T) where T<:AbstractArray at abstractarray.jl:14
  convert(::Type{T}, ::LinearAlgebra.Factorization) where T<:AbstractArray at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\factorization.jl:55
  ...
Stacktrace:
 [1] outer(::Int64, ::Nothing, ::Document) at .\REPL[3]:1
 [2] outer(::Document) at C:\Users\znidar\.julia\packages\AcuteML\bfP7i\src\@aml\@aml_create\get_struct_xml_.jl:53
 [3] top-level scope at REPL[15]:1`

I checked example in documentation (it works ), however this one not. No idea what else to check.

Simon

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.88. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

aminya commented 4 years ago

Thanks for reporting this. I need to debug the issue.

aminya commented 3 years ago

@szafna

You need to specify the component name whenever it is defined using another @aml.

~ is only useful when the julia name is the same as XML name.

The following works fine:

using AcuteML

@aml mutable struct inner "~"
    id1::Int, att"~"
    desc1::String, "~"
end

@aml mutable struct outer doc"outer"
    id2::Int, att"~"
    innerList::Vector{inner}, "inner" # <--- notice this
end

i1 = inner(id1 = 1, desc1 = "desc1")
i2 = inner(id1 = 2, desc1 = "desc2")
o1 = outer(id2 = 3, innerList = [i1, i2])
pprint(o1)

pprint("./o1.xml", o1)

xml = readxml("./o1.xml")

o2 = outer(xml)
aminya commented 3 years ago

I added more information to the simple example to prevent confusion.

szafna commented 3 years ago

Thx. It is working.