-
Notifications
You must be signed in to change notification settings - Fork 525
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
Implicit operator for Color to to enable int assignment #4120
Merged
Conversation
This file contains 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
it enables: Color c = -65536; //Red Simple conversion and intuitive since Color can be assigned to int parameter/field, vice versa shall be available.
gugavaro
approved these changes
Jan 15, 2020
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
There is a problem with this PR. Consider this code which calls
This code compiles Just Fine with d16-5, but with this change it results in a CS0172 error:
Oops. I fear we'll need to revert, as otherwise this would be an source compatibility change. |
gugavaro
pushed a commit
that referenced
this pull request
Feb 24, 2020
jonpryor
pushed a commit
that referenced
this pull request
Feb 25, 2020
…4315) There was an unforeseen complication in commit 1d5ed48: circular conversions. Before 1d5ed48, `Android.Graphics.Color` had an implicit conversion from `Color` to `int`. Commit 1d5ed48 added an implicit conversion from `int` to `Color`. Thus: partial struct Color { public static implicit operator Color (int value); public static implicit operator int (Color value); } This *seems* fine, but is problematic within ternary expressions: Color c1 = ... int c2 = ...; var c = condition ? c1 : c2; This results in a [CS0172 error][0]: error CS0172: Type of conditional expression cannot be determined because 'Color' and 'int' implicitly convert to one another In short, adding an implicit conversion from `int` to `Color` results in a source compatibility break. [Xamarin.Forms ran into this breakage][1]: SetScrimColor(isShowingSplit ? Color.Transparent.ToAndroid() : (int)DefaultScrimColor); There are two potential fixes: 1. Make the implicit `int`-to-`Color` operator *`explicit`*, or 2. Remove the added operator entirely. At this point in time, we see little benefit to making the operator `explicit`, so we have opted to remove the operator by reverting commit 1d5ed48. [0]: https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0172 [1]: https://github.com/xamarin/Xamarin.Forms/blob/7a52542d50797ccc69ae1d8dd84259190d96bdb4/Xamarin.Forms.Platform.Android/Renderers/MasterDetailRenderer.cs#L425
jonpryor
pushed a commit
that referenced
this pull request
Feb 25, 2020
…4315) There was an unforeseen complication in commit 1d5ed48: circular conversions. Before 1d5ed48, `Android.Graphics.Color` had an implicit conversion from `Color` to `int`. Commit 1d5ed48 added an implicit conversion from `int` to `Color`. Thus: partial struct Color { public static implicit operator Color (int value); public static implicit operator int (Color value); } This *seems* fine, but is problematic within ternary expressions: Color c1 = ... int c2 = ...; var c = condition ? c1 : c2; This results in a [CS0172 error][0]: error CS0172: Type of conditional expression cannot be determined because 'Color' and 'int' implicitly convert to one another In short, adding an implicit conversion from `int` to `Color` results in a source compatibility break. [Xamarin.Forms ran into this breakage][1]: SetScrimColor(isShowingSplit ? Color.Transparent.ToAndroid() : (int)DefaultScrimColor); There are two potential fixes: 1. Make the implicit `int`-to-`Color` operator *`explicit`*, or 2. Remove the added operator entirely. At this point in time, we see little benefit to making the operator `explicit`, so we have opted to remove the operator by reverting commit 1d5ed48. [0]: https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0172 [1]: https://github.com/xamarin/Xamarin.Forms/blob/7a52542d50797ccc69ae1d8dd84259190d96bdb4/Xamarin.Forms.Platform.Android/Renderers/MasterDetailRenderer.cs#L425
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
it enables:
Color c = -65536; //Red
Simple conversion and intuitive since Color can be assigned to int parameter/field, vice versa shall be available.