-
Notifications
You must be signed in to change notification settings - Fork 509
Fix direction of variance check in delegate assignment #4945
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
{ | ||
call instance void [System.Runtime]System.Object::.ctor() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a nit, but doesn't this require the this pointer to be loaded first? It's not really a problem, since this method is not verified anyway, but I think it is still good practice to keep the non-invalid IL code valid in these test files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, looks like I mangled it. Thanks :-) By the way, I'd love to sync up (email or skype) at some point, so that we're not duplicating efforts. Would you mind contacting me ([email protected])? Cheers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll send you a message. |
||
nop | ||
ret | ||
} | ||
} |
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.