Remove symbol overloads of Colorize color methods for symbol auto-casting#11775
Draft
straight-shoota wants to merge 2 commits intocrystal-lang:masterfrom
Draft
Remove symbol overloads of Colorize color methods for symbol auto-casting#11775straight-shoota wants to merge 2 commits intocrystal-lang:masterfrom
Colorize color methods for symbol auto-casting#11775straight-shoota wants to merge 2 commits intocrystal-lang:masterfrom
Conversation
Co-Authored-By: r00ster91 <r00ster91@protonmail.com>
jkthorne
reviewed
Jan 27, 2022
| self | ||
| end | ||
|
|
||
| def on(color : Symbol) |
Contributor
There was a problem hiding this comment.
should there be a deprecation warning for this?
Contributor
There was a problem hiding this comment.
As mentioned in the OP, the mere existence of a Symbol-accepting overload will trigger deprecations even for arguments that autocast to Color due to overload ordering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Colorizemethods receiving a color (#foreand#back) have overloads receiving aSymbolparameter which is manually mapped to values ofColorANSI. This implementation predates the symbol auto-casting of enum values.This patch removes the overloads with
Symboltyped parameters which leaves the overloads receiving aColorparameter. This type is a union including the enumColorANSIwhich enables symbol auto-casting for color values.The problem is: it's a breaking change. If the API is used with symbols that are not directly created from literals, there will be a compile time error. This is good and intended because it adds type safety (you can know at compile time whether a value is valid). But it's still a breaking change that destroys valid use cases which would require changes to user code (as demonstrated by the changes in
samples/2048.crandsrc/spec/dsl.crfor example). So I believe we can't merge it just like that.The only option is to leave the removed overloads in with a deprecation notice. That's not ideal though because the deprecation warning even triggers for usages that are compatible with the auto-casting method. But the symbol overload takes precedence over auto-casting. The only way to deactivate deprecation warnings is using a named argument:
fore(fore: :green).Are there any other ideas? We could use a feature flag but I think would be silly for such a minor thing.
This patch has been extracted from #7690.