Skip to content

IllegalDispatch instead of wildcard match with ADT #43

@visr

Description

@visr

I don't expect an IllegalDispatch error here, I expected the wildcard to match:

using Moshi.Data: @data
using Moshi.Match: @match

@data ADT begin
    A
    B
end

is_a(x) = @match x begin
    ADT.A() => true
    _ => false
end

is_a(ADT.A())  # -> true, as expected
is_a(ADT.B())  # -> false, as expected
is_a(nothing)
ERROR: illegal dispatch, expect to be overloaded by @data: got Nothing for Main.ADT.A
Stacktrace:
 [1] isa_variant(x::Nothing, variant::Type)
   @ Moshi.Data C:\ProgramData\DevDrives\.julia\packages\Moshi\SEGHC\src\data\runtime.jl:185
 [2] is_a(x::Nothing)
   @ Main c:\ProgramData\DevDrives\.julia\dev\SciMLBase\try.jl:23

A workaround for now would be using to us dispatch:

is_a(x::ADT.Type) = @match x begin
    ADT.A() => true
    _ => false
end

is_a(x::Any) = false

Came up in SciML/SciMLBase.jl#945

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions