-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Specially handle more scenarios for type parameters with 'allows ref struct' constraint #73111
Changes from 1 commit
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 |
---|---|---|
|
@@ -2829,7 +2829,8 @@ public bool HasImplicitTypeParameterConversion(TypeParameterSymbol source, TypeS | |
return true; | ||
} | ||
|
||
if ((destination.TypeKind == TypeKind.TypeParameter) && | ||
if (destination is TypeParameterSymbol { AllowByRefLike: false } && | ||
!source.AllowByRefLike && | ||
source.DependsOn((TypeParameterSymbol)destination)) | ||
{ | ||
return true; | ||
|
@@ -2848,7 +2849,10 @@ private bool HasImplicitReferenceTypeParameterConversion(TypeParameterSymbol sou | |
return false; // Not a reference conversion. | ||
} | ||
|
||
// PROTOTYPE(RefStructInterfaces): Check for AllowByRefLike? | ||
if (source.AllowByRefLike) | ||
{ | ||
return false; | ||
} | ||
|
||
// The following implicit conversions exist for a given type parameter T: | ||
// | ||
|
@@ -2868,7 +2872,7 @@ private bool HasImplicitReferenceTypeParameterConversion(TypeParameterSymbol sou | |
} | ||
|
||
// * From T to a type parameter U, provided T depends on U. | ||
if ((destination.TypeKind == TypeKind.TypeParameter) && | ||
if (destination is TypeParameterSymbol { AllowByRefLike: false } && | ||
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. 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.
Why do you think it should be sufficient? Dependency between type parameters says nothing about their |
||
source.DependsOn((TypeParameterSymbol)destination)) | ||
{ | ||
return true; | ||
|
@@ -3221,8 +3225,8 @@ private bool HasImplicitBoxingTypeParameterConversion(TypeParameterSymbol source | |
} | ||
|
||
// SPEC: From T to a type parameter U, provided T depends on U | ||
if ((destination.TypeKind == TypeKind.TypeParameter) && | ||
source.DependsOn((TypeParameterSymbol)destination)) | ||
if (destination is TypeParameterSymbol { AllowByRefLike: false } d && | ||
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. 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.
Same response as for the change on line 2875 |
||
source.DependsOn(d)) | ||
{ | ||
return true; | ||
} | ||
|
@@ -3280,7 +3284,7 @@ public bool HasBoxingConversion(TypeSymbol source, TypeSymbol destination, ref C | |
// There are a couple of exceptions. The very special types ArgIterator, ArgumentHandle and | ||
// TypedReference are not boxable: | ||
|
||
if (source.IsRestrictedType()) // PROTOTYPE(RefStructInterfaces): Is this doing the right thing for 'allows ref struct' type parameters? | ||
if (source.IsRestrictedType()) | ||
{ | ||
return false; | ||
} | ||
|
@@ -3476,6 +3480,11 @@ private bool HasExplicitReferenceTypeParameterConversion(TypeSymbol source, Type | |
TypeParameterSymbol s = source as TypeParameterSymbol; | ||
TypeParameterSymbol t = destination as TypeParameterSymbol; | ||
|
||
if (s?.AllowByRefLike == true || t?.AllowByRefLike == true) | ||
{ | ||
return false; | ||
} | ||
|
||
// SPEC: The following explicit conversions exist for a given type parameter T: | ||
|
||
// SPEC: If T is known to be a reference type, the conversions are all classified as explicit reference conversions. | ||
|
@@ -3523,6 +3532,11 @@ private bool HasUnboxingTypeParameterConversion(TypeSymbol source, TypeSymbol de | |
TypeParameterSymbol s = source as TypeParameterSymbol; | ||
TypeParameterSymbol t = destination as TypeParameterSymbol; | ||
|
||
if (s?.AllowByRefLike == true || t?.AllowByRefLike == true) | ||
{ | ||
return false; | ||
} | ||
|
||
// SPEC: The following explicit conversions exist for a given type parameter T: | ||
|
||
// SPEC: If T is known to be a reference type, the conversions are all classified as explicit reference conversions. | ||
|
@@ -3753,7 +3767,7 @@ private bool HasUnboxingConversion(TypeSymbol source, TypeSymbol destination, re | |
} | ||
|
||
// Ref-like types cannot be boxed or unboxed | ||
if (destination.IsRestrictedType()) // PROTOTYPE(RefStructInterfaces): Is this doing the right thing for 'allows ref struct' type parameters? | ||
if (destination.IsRestrictedType()) | ||
{ | ||
return false; | ||
} | ||
|
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.
Are we testing this case? #Resolved
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 tried, but given the convoluted nature of the conversion classification algorithms, I was not able to find a scenario where we get here with
source.AllowByRefLike
equalstrue
. Nevertheless, I am fairly comfortable making this change regardless of the fact.