Skip to content

Interpreter crashes with missing downcast_distinct from String to (Int32 | String) #16484

@cyangle

Description

@cyangle

Found this interpreter bug with crystal-db shard.

Reduced code to reproduce:

require "log"

module MetadataValueConverter
  def self.arg_to_log(arg) : ::Log::Metadata::Value
    ::Log::Metadata::Value.new(arg.to_s)
  end

  def self.arg_to_log(arg : Enumerable) : ::Log::Metadata::Value
    ::Log::Metadata::Value.new(arg.to_a.map { |a| arg_to_log(a) })
  end

  def self.arg_to_log(arg : Int) : ::Log::Metadata::Value
    ::Log::Metadata::Value.new(arg.to_i64)
  end

  def self.arg_to_log(arg : Int32 | String) : ::Log::Metadata::Value
    ::Log::Metadata::Value.new(arg)
  end
end

args = [1, nil, "a"]
MetadataValueConverter.arg_to_log(args)

Prints below error:

In local/missing_downcast.cr:9:51

 9 | ::Log::Metadata::Value.new(arg.to_a.map { |a| arg_to_log(a) })
                                                   ^---------
Error: BUG: missing downcast_distinct from String to (Int32 | String) (Crystal::NonGenericClassType to Crystal::MixedUnionType)

Shouldn't this be an upcast instead of downcast?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions