You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes when designing an API, one wants to have a pair of public functions, where one is meant to be called by users, while the other is for users to overload (add methods to). An example in Base is the promote_type and promote_rule function pair. The promote_typedoc string is clear about users being forbidden from overloading this function:
Don't overload this directly
To overload promotion for your own types you should overload promote_rule.
There is a hidden field of MethodTable that can be set to enable this (it exists for Builtin, as the runtime would likely segfault if someone unintentionally added a Method there). It is almost certainly not stable, but may be useful anyways to set inside Base, where overloading the wrong method may be common and lead to confusion (eg perhaps promote_type) or bugs (eg perhaps typejoin). However, it currently isn't general enough to prevent abusing getproperty to introduce unsoundness either, as it works at the MethodTable level, not on particular Methods
Motivation
Sometimes when designing an API, one wants to have a pair of public functions, where one is meant to be called by users, while the other is for users to overload (add methods to). An example in
Base
is thepromote_type
andpromote_rule
function pair. Thepromote_type
doc string is clear about users being forbidden from overloading this function:Still, many packages do overload
promote_type
:https://juliahub.com/ui/Search?q=promote_type&type=symbols&u=define&t=function
Proposed solutions
Some alternatives:
Nota bene
This issue arguably ties into the function/method sealing issue: #31222.
This issue arguably ties into the API specification issue: #49973.
The text was updated successfully, but these errors were encountered: