Skip to content

TODO: v2 API: Support converting types in setters #21

@ghost

Description

In old salsa this was supported, but in the new v2 API it's not:

julia> rt = Runtime()
Salsa.Runtime(Salsa.DefaultStorage(0, ...))

julia> @declare_input x(rt)::Int
(x, set_x!, delete_x!)

julia> set_x!(rt, 2.0)
ERROR: MethodError: no method matching set_x!(::Salsa._TopLevelRuntime{Salsa.EmptyContext,Salsa._DefaultSalsaStorage.DefaultStorage}, ::Float64)
Closest candidates are:
  set_x!(::Any, ::Int64) at /Users/nathandaly/.julia/dev/Salsa/src/Salsa.jl:773
Stacktrace:
 [1] top-level scope at REPL[34]:1

julia> @declare_input a(rt)::Vector{Int}
(a, set_a!, delete_a!)

julia> set_a!(rt, [])
ERROR: MethodError: no method matching set_a!(::Salsa._TopLevelRuntime{Salsa.EmptyContext,Salsa._DefaultSalsaStorage.DefaultStorage}, ::Array{Any,1})
Closest candidates are:
  set_a!(::Any, ::Array{Int64,1}) at /Users/nathandaly/.julia/dev/Salsa/src/Salsa.jl:773
Stacktrace:
 [1] top-level scope at REPL[41]:1

julia>

This should be very simple; I think we just need to call convert(T, v) in the generated setters. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions