-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Make remaining managed pointer type scenarios warnings #64294
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -1393,7 +1393,7 @@ private BoundExpression BindSizeOf(SizeOfExpressionSyntax node, BindingDiagnosti | |
| TypeWithAnnotations typeWithAnnotations = this.BindType(typeSyntax, diagnostics, out alias); | ||
| TypeSymbol type = typeWithAnnotations.Type; | ||
|
|
||
| bool typeHasErrors = type.IsErrorType() || CheckManagedAddr(Compilation, type, warnForManaged: false, node.Location, diagnostics); | ||
| bool typeHasErrors = type.IsErrorType() || CheckManagedAddr(Compilation, type, node.Location, diagnostics); | ||
|
|
||
| BoundTypeExpression boundType = new BoundTypeExpression(typeSyntax, alias, typeWithAnnotations, typeHasErrors); | ||
| ConstantValue constantValue = GetConstantSizeOf(type); | ||
|
|
@@ -1403,31 +1403,29 @@ private BoundExpression BindSizeOf(SizeOfExpressionSyntax node, BindingDiagnosti | |
| } | ||
|
|
||
| /// <returns>true if managed type-related errors were found, otherwise false.</returns> | ||
| internal static bool CheckManagedAddr(CSharpCompilation compilation, TypeSymbol type, bool warnForManaged, Location location, BindingDiagnosticBag diagnostics) | ||
| internal static bool CheckManagedAddr(CSharpCompilation compilation, TypeSymbol type, Location location, BindingDiagnosticBag diagnostics, bool errorForManaged = false) | ||
| { | ||
| var useSiteInfo = new CompoundUseSiteInfo<AssemblySymbol>(diagnostics, compilation.Assembly); | ||
| var managedKind = type.GetManagedKind(ref useSiteInfo); | ||
| diagnostics.Add(location, useSiteInfo); | ||
|
|
||
| return CheckManagedAddr(compilation, type, managedKind, warnForManaged, location, diagnostics); | ||
| return CheckManagedAddr(compilation, type, managedKind, location, diagnostics, errorForManaged); | ||
| } | ||
|
|
||
| /// <returns>true if managed type-related errors were found, otherwise false.</returns> | ||
| internal static bool CheckManagedAddr(CSharpCompilation compilation, TypeSymbol type, ManagedKind managedKind, bool warnForManaged, Location location, BindingDiagnosticBag diagnostics) | ||
| internal static bool CheckManagedAddr(CSharpCompilation compilation, TypeSymbol type, ManagedKind managedKind, Location location, BindingDiagnosticBag diagnostics, bool errorForManaged = false) | ||
| { | ||
| switch (managedKind) | ||
| { | ||
| case ManagedKind.Managed: | ||
| if (warnForManaged) | ||
| { | ||
| diagnostics.Add(ErrorCode.WRN_ManagedAddr, location, type); | ||
| return false; | ||
| } | ||
| else | ||
| if (errorForManaged) | ||
| { | ||
| diagnostics.Add(ErrorCode.ERR_ManagedAddr, location, type); | ||
| return true; | ||
| } | ||
|
|
||
| diagnostics.Add(ErrorCode.WRN_ManagedAddr, location, type); | ||
| return false; | ||
|
Contributor
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.
Contributor
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. If not, the method comment should be updated to reflect the new behavior. |
||
| case ManagedKind.UnmanagedWithGenerics when MessageID.IDS_FeatureUnmanagedConstructedTypes.GetFeatureAvailabilityDiagnosticInfo(compilation) is CSDiagnosticInfo diagnosticInfo: | ||
| diagnostics.Add(diagnosticInfo, location); | ||
| return true; | ||
|
|
@@ -2233,7 +2231,7 @@ private BoundBaseReference BindBase(BaseExpressionSyntax node, BindingDiagnostic | |
| private BoundExpression BindCast(CastExpressionSyntax node, BindingDiagnosticBag diagnostics) | ||
| { | ||
| BoundExpression operand = this.BindValue(node.Expression, diagnostics, BindValueKind.RValue); | ||
| TypeWithAnnotations targetTypeWithAnnotations = this.WithAdditionalFlags(BinderFlags.AllowManagedPointer).BindType(node.Type, diagnostics); | ||
| TypeWithAnnotations targetTypeWithAnnotations = this.BindType(node.Type, diagnostics); | ||
| TypeSymbol targetType = targetTypeWithAnnotations.Type; | ||
|
|
||
| if (targetType.IsNullableType() && | ||
|
|
@@ -3313,7 +3311,7 @@ private BoundExpression BindImplicitStackAllocArrayCreationExpression(ImplicitSt | |
|
|
||
| if (!bestType.IsErrorType()) | ||
| { | ||
| CheckManagedAddr(Compilation, bestType, warnForManaged: false, node.Location, diagnostics); | ||
| CheckManagedAddr(Compilation, bestType, node.Location, diagnostics, errorForManaged: true); | ||
| } | ||
|
|
||
| return BindStackAllocWithInitializer( | ||
|
|
@@ -3670,7 +3668,7 @@ private BoundExpression BindStackAllocArrayCreationExpression( | |
| TypeSymbol type = GetStackAllocType(node, elementType, diagnostics, out bool hasErrors); | ||
| if (!elementType.Type.IsErrorType()) | ||
| { | ||
| hasErrors = hasErrors || CheckManagedAddr(Compilation, elementType.Type, warnForManaged: false, elementTypeSyntax.Location, diagnostics); | ||
| hasErrors = hasErrors || CheckManagedAddr(Compilation, elementType.Type, elementTypeSyntax.Location, diagnostics, errorForManaged: true); | ||
| } | ||
|
|
||
| SyntaxList<ArrayRankSpecifierSyntax> rankSpecifiers = arrayTypeSyntax.RankSpecifiers; | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
We should also do a LangVersion check so that people on old language versions can't suppress these #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 think that's a good idea. I'll do a
runtimerebuild tonight to verify they don't have a project with managed pointers and LangVer<11.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.
Following conversation with Jared, I added a LangVer check. Thanks