-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Copy link
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.topic:compiler:interpreter
Description
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
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.topic:compiler:interpreter