This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 509
Fix direction of variance check in delegate assignment #4945
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
.assembly extern System.Runtime | ||
{ | ||
} | ||
|
||
.assembly DelegateTests | ||
{ | ||
} | ||
|
||
.class private auto ansi beforefieldinit C | ||
extends [System.Runtime]System.Object | ||
{ | ||
// assignment from Func<int, string> to Func<int, object> is valid | ||
.method private hidebysig instance class [System.Runtime]System.Func`2<int32,object> | ||
DelegateAssignmentReturn_Valid(class [System.Runtime]System.Func`2<int32,string> input) cil managed | ||
{ | ||
ldarg.1 | ||
ret | ||
} | ||
|
||
// assignment from Func<object, int> to Func<string, int> is valid | ||
.method private hidebysig instance class [System.Runtime]System.Func`2<string,int32> | ||
DelegateAssignmentParameter_Valid(class [System.Runtime]System.Func`2<object,int32> input) cil managed | ||
{ | ||
ldarg.1 | ||
ret | ||
} | ||
|
||
// assignment from Func<string, int> to Func<object, int> is invalid | ||
.method private hidebysig instance class [System.Runtime]System.Func`2<object,int32> | ||
DelegateAssignmentParameter_Invalid_StackUnexpected(class [System.Runtime]System.Func`2<string,int32> input) cil managed | ||
{ | ||
ldarg.1 | ||
ret | ||
} | ||
|
||
// assignment from Func<int, object> to Func<int, string> is invalid | ||
.method private hidebysig instance class [System.Runtime]System.Func`2<int32,string> | ||
DelegateAssignment_Invalid_StackUnexpected(class [System.Runtime]System.Func`2<int32,object> input) cil managed | ||
{ | ||
ldarg.1 | ||
ret | ||
} | ||
|
||
.method public hidebysig specialname rtspecialname | ||
instance void .ctor() cil managed | ||
{ | ||
ldarg.0 | ||
call instance void [System.Runtime]System.Object::.ctor() | ||
ret | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically the types should be "Compatible". In the spec "Compatible" is more strict than "Assignable", since "Assignable" allows some reinterpretations. I.E. an
int32
is Assignable toint8
- one can be assigned to another with implicit value truncation.However
int32
andint8
are not "Compatible" and thereforeint M1()
cannot be used asFunc<byte>
I am not sure what
IsAssignable
implements. It could as well implement "IsCompatible", then everything is correct.Perhaps it is worth adding a test while touching this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry - I have not noticed that you have commented on this before merging. I agree it would be nice to add test for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed follow-up issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not block merging on this. Just a good thing to have.