Custom `constructor` on `Types::Nominal::Any` doesn't always get called
Describe the bug
A custom constructor defined on a custom type extending Types::Nominal::Any doesn't always get called when used in the context of a Dry Schema. Constructor's on other non-Any types seem to get called as expected, and the constructor gets called when using the type directly, so this seemed inconsistent that the Any constructor doesn't always get called when used with dry-schema.
To Reproduce
require "dry-types"
require "dry-schema"
module Types
include Dry.Types()
CustomAnyType = Types::Nominal::Any.constructor do |value|
puts "DEBUG ANY: #{value.inspect}"
value
end
CustomStringType = Types::Nominal::String.constructor do |value|
puts "DEBUG STRING: #{value.inspect}"
value
end
CustomIntegerType = Types::Nominal::Integer.constructor do |value|
puts "DEBUG INTEGER: #{value.inspect}"
value
end
end
schema = Dry::Schema.Params do
required(:any).value(Types::CustomAnyType)
required(:any_constrained).value(Types::CustomAnyType.constrained(included_in: ["abc", "def"]))
required(:string).value(Types::CustomStringType)
required(:integer).value(Types::CustomIntegerType)
end
puts "=== BEGIN DRY-TYPES CALLS ==="
Types::CustomAnyType["foo"]
Types::CustomStringType["bar"]
Types::CustomIntegerType[10]
puts "\n\n=== BEGIN DRY-SCHEMA CALL #1 ==="
schema.call(
any: "foo",
string: "bar",
integer: 10
)
puts "\n\n=== BEGIN DRY-SCHEMA CALL #2 ==="
schema.call(
any_constrained: "foo",
string: "bar",
integer: 10
)
In the output, you can see that DEBUG ANY is printed when using CustomAnyType directly as a plain type. It also gets called if the CustomAnyType is combined with custom constraints. However, in the default case under BEGIN DRY-SCHEMA CALL #1, the CustomAnyType's constructor doesn't appear to be called at all:
=== BEGIN DRY-TYPES CALLS ===
DEBUG ANY: "foo"
DEBUG STRING: "bar"
DEBUG INTEGER: 10
=== BEGIN DRY-SCHEMA CALL #1 ===
DEBUG STRING: "bar"
DEBUG INTEGER: 10
=== BEGIN DRY-SCHEMA CALL #2 ===
DEBUG ANY: "foo"
DEBUG STRING: "bar"
DEBUG INTEGER: 10
Expected behavior
In the above example, for BEGIN DRY-SCHEMA CALL #1, I would expect that the CustomAnyType constructor to be called, so the output would match the others:
=== BEGIN DRY-SCHEMA CALL #1 ===
DEBUG ANY: "foo"
DEBUG STRING: "bar"
DEBUG INTEGER: 10
My environment
- Affects my production application: YES
- Ruby version: 3.4.6
- OS: Debian Bookworm