-
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 #73232
Changes from 3 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 |
---|---|---|
|
@@ -3568,8 +3568,35 @@ internal static ConstantValue GetIsOperatorConstantResult( | |
|
||
// * If either type is a restricted type, the type check isn't supported because | ||
AlekseyTs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// a restricted type cannot be boxed or unboxed into. | ||
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. Consider adjusting this comment to reflect the implementation changes. #Resolved |
||
if (targetType.IsRestrictedType() || operandType.IsRestrictedType()) // PROTOTYPE(RefStructInterfaces): Is this doing the right thing for 'allows ref struct' type parameters? | ||
if (targetType.IsRestrictedType() || operandType.IsRestrictedType()) | ||
{ | ||
if (targetType is TypeParameterSymbol { AllowByRefLike: true }) | ||
{ | ||
if (!operandType.IsRefLikeType && operandType is not TypeParameterSymbol) | ||
{ | ||
return null; | ||
} | ||
} | ||
else if (operandType is not TypeParameterSymbol { AllowByRefLike: true }) | ||
{ | ||
if (targetType.IsRefLikeType) | ||
{ | ||
if (operandType is TypeParameterSymbol) | ||
{ | ||
Debug.Assert(operandType is TypeParameterSymbol { AllowByRefLike: false }); | ||
return ConstantValue.False; | ||
} | ||
} | ||
else if (operandType.IsRefLikeType) | ||
{ | ||
if (targetType is TypeParameterSymbol) | ||
{ | ||
Debug.Assert(targetType is TypeParameterSymbol { AllowByRefLike: false }); | ||
return ConstantValue.False; | ||
} | ||
} | ||
} | ||
|
||
return ConstantValue.Bad; | ||
} | ||
|
||
|
@@ -3981,6 +4008,11 @@ internal static ConstantValue GetAsOperatorConstantResult(TypeSymbol operandType | |
|
||
if (!isOperatorConstantResult.BooleanValue) | ||
{ | ||
if (operandType?.IsRefLikeType == true) | ||
{ | ||
return ConstantValue.Bad; | ||
} | ||
|
||
return ConstantValue.Null; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -752,7 +752,6 @@ internal MethodSymbol TryFindDisposePatternMethod(BoundExpression expr, SyntaxNo | |
{ | ||
Debug.Assert(expr is object); | ||
Debug.Assert(expr.Type is object); | ||
// PROTOTYPE(RefStructInterfaces): adjust? | ||
Debug.Assert(expr.Type.IsRefLikeType || hasAwait); // pattern dispose lookup is only valid on ref structs or asynchronous usings | ||
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. Is pattern dispose not allowed on 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.
I think |
||
|
||
var result = PerformPatternMethodLookup(expr, | ||
|
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
ErrorCode.ERR_AnonDelegateCantUseLocal
? #ResolvedThere 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.
No, I think this code path is covered by a test for
ERR_AnonDelegateCantUseRefLike
.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 will add the following test in the next PR: