Skip to content

MethodError(f=typeof(Core.Compiler.fieldindex() #32959

@erathorn

Description

@erathorn

I have the following piece of code where I try to extend the type system by a TreeStochastic type.

module my_mod



abstract type ScalarVariate <: Real end
abstract type ArrayVariate{N} <: DenseArray{Float64, N} end
abstract type TreeVariate <: Any end

const AbstractVariate = Union{ScalarVariate, ArrayVariate, TreeVariate}

#################### My Types ####################

mutable struct Node
    name::String
    data::Array{Float64,2}
end

mutable struct ScalarLogical <: ScalarVariate
  value::Float64
  symbol::Symbol
end

mutable struct ArrayLogical{N} <: ArrayVariate{N}
  value::Array{Float64, N}
  symbol::Symbol
end

mutable struct ScalarStochastic <: ScalarVariate
  value::Float64
  symbol::Symbol
end

mutable struct ArrayStochastic{N} <: ArrayVariate{N}
  value::Array{Float64, N}
  symbol::Symbol
end

mutable struct TreeStochastic <: TreeVariate
    value::Node
    symbol::Symbol
end

const AbstractLogical = Union{ScalarLogical, ArrayLogical}
const AbstractStochastic = Union{ScalarStochastic, ArrayStochastic, TreeStochastic}
const AbstractDependent = Union{AbstractLogical, AbstractStochastic}


Base.size(v::AbstractVariate) = size(v.value)

function Stochastic(d::Integer)
  if d == 0
    value = Float64(NaN)
    s = ScalarStochastic(value, :nothing)
  else
    value = Array{Float64}(undef, fill(0,d)...)
    s = ArrayStochastic(value, :nothing)
  end
  s
end

function Logical(d::Integer)
  if d == 0
    value = Float64(NaN)
    s = ScalarLogical(value, :nothing)
  else
    value = Array{Float64}(undef, fill(0,d)...)
    s = ArrayLogical(value, :nothing)
  end
  s
end

function Stochastic(d::AbstractString)
  TreeStochastic(Node("",zeros(Float64,(1,2))), :nothing)
end

function Model(; nodes...)
  nodedict = Dict{Symbol, Any}()
  for (key, value) in nodes
    isa(value, AbstractDependent) || throw(ArgumentError("nodes are not all Dependent types"))
    node = deepcopy(value)
    node.symbol = key
    nodedict[key] = node
  end
  nodedict
end

end

Upon calling the module and executing the function Model, I get an Internal error message:

Internal error: encountered unexpected error in runtime: MethodError(f=typeof(Core.Compiler.fieldindex)(), args=(my_mod.ArrayLogical{N} where N, :symbol, false), world=0x0000000000000eb9)

The function is called like this:

include("f1.jl")
using .my_mod
my_mod.Model(y=my_mod.Stochastic(1),x=my_mod.Logical(2), z=my_mod.Stochastic("t"))

If I run the function without z=my_mod.Stochastic("t") everything works as expected.

Further observations:

  • When called a second time the error does not show up.
  • When called within the Juno debugger environment the error also does not show up

Here is my output of versioninfo()

Julia Version 1.1.1
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, haswell)
Environment:
JULIA_EDITOR = "C:\Users\Johannes\AppData\Local\atom\app-1.40.0\atom.exe" -a
JULIA_NUM_THREADS = 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions