JuliaDynamics/Agents.jl

Syntax check of `@multiagent` is not as correct as it should be:

Closed this issue · 3 comments

MWE:

@multiagent struct MultiSchelling{X}(GridAgent{2})
    @agent struct Civilian # can't re-define existing `Schelling` name
        mood::Bool = false
        group::Int
    end
    @agent struct Governor{X<:Real} # can't redefine existing `Politician` name
        group::Int
        influence::X
    end
end

civ = Civilian(; id = 2, pos = (2, 2), group = 2) # default `mood`

gov = Governor(; id = 3 , pos = (2, 2), group = 2, influence = 0.5)

the gov line errors with

ERROR: MethodError: Cannot `convert` an object of type Float64 to an object of type MixedStructTypes.Uninitialized

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84

Stacktrace:
 [1] MultiSchelling{…}(id::Int64, pos::Tuple{…}, mood::MixedStructTypes.Uninitialized, group::Int64, influence::Float64, type#226::Symbol)
   @ Main C:\Users\datse\.julia\packages\MixedStructTypes\U6UR1\src\CompactStructTypes.jl:51
 [2] Governor(; id::Int64, pos::Tuple{Int64, Int64}, group::Int64, influence::Float64)
   @ Main C:\Users\datse\.julia\packages\MixedStructTypes\U6UR1\src\CompactStructTypes.jl:104
 [3] top-level scope
   @ c:\Users\datse\.julia\dev\Agents\docs\src\tutorial.jl:737
Some type information was truncated. Use `show(err)` to see complete types.

it is because I did {X} in the super type but {X<:Real} in the subtype.

I guess we could even allow this syntax if we want to, I think that again it should be done in MixedStructTypes.jl

This works with :opt_speed after #972, but still doesn't with the other version

Should be now fixed for all cases