Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove overloading promote_type #426

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lgoettgens
Copy link

Resolves #425 in the way that is outlined in the docstrings

help?> Base.promote_type
  promote_type(type1, type2, ...)

  Promotion refers to converting values of mixed types to a single common type.
  promote_type represents the default promotion behavior in Julia when operators (usually
  mathematical) are given arguments of differing types. promote_type generally tries to
  return a type which can at least approximate most values of either input type without
  excessively widening. Some loss is tolerated; for example, promote_type(Int64, Float64)
  returns Float64 even though strictly, not all Int64 values can be represented exactly as
  Float64 values.

  See also: promote, promote_typejoin, promote_rule.

  [...]

  │ Don't overload this directly
  │
  │  To overload promotion for your own types you should overload promote_rule.
  │  promote_type calls promote_rule internally to determine the type. Overloading
  │  promote_type directly can cause ambiguity errors.

help?> Base.promote_rule
  promote_rule(type1, type2)

  Specifies what type should be used by promote when given values of types type1 and type2.
  This function should not be called directly, but should have definitions added to it for
  new types as appropriate.

@barche
Copy link
Collaborator

barche commented Apr 28, 2024

This change results in the error:

 basic_types: Error During Test at /home/runner/work/CxxWrap.jl/CxxWrap.jl/test/basic_types.jl:166
  Test threw exception
  Expression: typeof(a + a) == CxxWrap.CxxWrapCore.julia_int_type(CxxChar)
  promotion of types CxxChar and CxxChar failed to change any arguments

If I remember correctly that is also the reason I opted to override promote_type, but I am open to better solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

promote_type is not supposed to be overloaded
2 participants