mauro3/Parameters.jl

MethodError: no method matching stripsubtypes(::Int64)

singularitti opened this issue · 1 comments

I am trying to define a type with Int or Symbol as its type parameters:

julia> @with_kw struct A{:x}
           a
       end
ERROR: LoadError: MethodError: no method matching stripsubtypes(::QuoteNode)
Closest candidates are:
  stripsubtypes(::Expr) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:152
  stripsubtypes(::Symbol) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:150
  stripsubtypes(::Array{T,1} where T) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:154
Stacktrace:
 [1] iterate at ./generator.jl:47 [inlined]
 [2] collect(::Base.Generator{Array{Any,1},typeof(Parameters.stripsubtypes)}) at ./array.jl:622
 [3] stripsubtypes(::Array{Any,1}) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:154
 [4] with_kw(::Expr, ::Module, ::Bool) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:463
 [5] @with_kw(::LineNumberNode, ::Module, ::Any) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:631
in expression starting at REPL[5]:1

julia> @with_kw struct B{2}
           a
       end
ERROR: LoadError: MethodError: no method matching stripsubtypes(::Int64)
Closest candidates are:
  stripsubtypes(::Expr) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:152
  stripsubtypes(::Symbol) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:150
  stripsubtypes(::Array{T,1} where T) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:154
Stacktrace:
 [1] iterate at ./generator.jl:47 [inlined]
 [2] collect(::Base.Generator{Array{Any,1},typeof(Parameters.stripsubtypes)}) at ./array.jl:622
 [3] stripsubtypes(::Array{Any,1}) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:154
 [4] with_kw(::Expr, ::Module, ::Bool) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:463
 [5] @with_kw(::LineNumberNode, ::Module, ::Any) at /Users/xxx/.julia/packages/Parameters/l76EM/src/Parameters.jl:631
in expression starting at REPL[4]:1

However, these are quite often used in type definitions. Hope these operations can be supported.

Parameters: v0.12.0

julia> versioninfo()
Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.6.0)
  CPU: Intel(R) Xeon(R) W-2140B CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 16
  JULIA_EDITOR = code

This is not how Julia works:

julia> struct A{:x}
                  a
              end
ERROR: syntax: invalid variable expression in "where"
Stacktrace:
 [1] top-level scope at REPL[1]:1

julia> struct A{2}
                  a
              end
ERROR: syntax: invalid type parameter name "2"
Stacktrace:
 [1] top-level scope at REPL[2]:1

The type-parameter is free and can be set later:

julia> struct A{T}
         a
       end

julia> A{2}
A{2}

julia> A{2}("a")
A{2}("a")

The docs are pretty good on types: https://docs.julialang.org/en/v1/manual/types/.