Skip to content
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

visual studio provider errors with use of field keyword - when typing #75893

Closed
UniqeId6542 opened this issue Nov 13, 2024 · 1 comment · Fixed by #75904
Closed

visual studio provider errors with use of field keyword - when typing #75893

UniqeId6542 opened this issue Nov 13, 2024 · 1 comment · Fixed by #75904
Assignees
Milestone

Comments

@UniqeId6542
Copy link

UniqeId6542 commented Nov 13, 2024

Version Used:
Visual Studio 17.12.0
c# project with language preview enabled

Steps to Reproduce:

  1. In a type in:
    private string? foo = null;
    public string Foo
    {
        get
        {
            if (this.foo is null)
            {
                FieldInfo field = typeof(String).GetField(nameof(string.Length), BindingFlags.Public | BindingFlags.Instance)!;
                this.foo = field.GetValue("hi");
            }

            return this.foo;
        }
    }
  1. When typeing in the field.GetValue part, many provider errors are produced by Visual Studio

Expected Behavior:
no provider errors

Actual Behavior:
The call stack of all of them looks similar enough that I'll only include one.

Errors in:

UnnamedSymbolCompletionProvider
ExtensionMethodImportCompletionProvider
PreprocessorCompletionProvider
TypeImportCompletionProvider
KeywordCompletionProvider
EnumAndCompletionListTagCompletionProvider
AwaitCompletionProvider
System.InvalidOperationException : Unexpected value 'FooProj.FooClass.Foo.get' of type 'Microsoft.CodeAnalysis.CSharp.Symbols.SourcePropertyAccessorSymbol'
at Microsoft.CodeAnalysis.CSharp.Binder.BindFieldExpression(FieldExpressionSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.g__bindExpressionInternal|337_0(ExpressionSyntax node,BindingDiagnosticBag diagnostics,Boolean invoked,Boolean indexed)
at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(ExpressionSyntax node,BindingDiagnosticBag diagnostics,Boolean invoked,Boolean indexed)
at Microsoft.CodeAnalysis.CSharp.Binder.BindExpression(ExpressionSyntax node,BindingDiagnosticBag diagnostics,Boolean invoked,Boolean indexed)
at Microsoft.CodeAnalysis.CSharp.Binder.BindLeftOfPotentialColorColorMemberAccess(ExpressionSyntax left,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindMemberAccess(MemberAccessExpressionSyntax node,Boolean invoked,Boolean indexed,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.g__bindExpressionInternal|337_0(ExpressionSyntax node,BindingDiagnosticBag diagnostics,Boolean invoked,Boolean indexed)
at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(ExpressionSyntax node,BindingDiagnosticBag diagnostics,Boolean invoked,Boolean indexed)
at Microsoft.CodeAnalysis.CSharp.Binder.BindExpression(ExpressionSyntax node,BindingDiagnosticBag diagnostics,Boolean invoked,Boolean indexed)
at Microsoft.CodeAnalysis.CSharp.Binder.BindAssignment(AssignmentExpressionSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.g__bindExpressionInternal|337_0(ExpressionSyntax node,BindingDiagnosticBag diagnostics,Boolean invoked,Boolean indexed)
at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(ExpressionSyntax node,BindingDiagnosticBag diagnostics,Boolean invoked,Boolean indexed)
at Microsoft.CodeAnalysis.CSharp.Binder.BindExpression(ExpressionSyntax node,BindingDiagnosticBag diagnostics,Boolean invoked,Boolean indexed)
at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionStatement(CSharpSyntaxNode node,ExpressionSyntax syntax,Boolean allowsAnyExpression,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionStatement(ExpressionStatementSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindStatement(StatementSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindBlockParts(BlockSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindBlock(BlockSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindStatement(StatementSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindPossibleEmbeddedStatement(StatementSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindIfStatement(IfStatementSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindStatement(StatementSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindBlockParts(BlockSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindBlock(BlockSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.Binder.BindStatement(StatementSyntax node,BindingDiagnosticBag diagnostics)
at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.EnsureNullabilityAnalysisPerformedIfNecessary()
at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetBoundNodes(CSharpSyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetLowerBoundNode(CSharpSyntaxNode node)
at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetBoundNodes(CSharpSyntaxNode node,CSharpSyntaxNode& bindableNode,BoundNode& lowestBoundNode,BoundNode& highestBoundNode,BoundNode& boundParent)
at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetTypeInfoWorker(CSharpSyntaxNode node,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.SpeculativeSemanticModelWithMemberModel.GetTypeInfoWorker(CSharpSyntaxNode node,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfo(ExpressionSyntax expression,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetTypeInfo(SemanticModel semanticModel,ExpressionSyntax expression,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery.SyntaxTokenExtensions.IsNumericTypeContext(SyntaxToken token,SemanticModel semanticModel,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery.CSharpSyntaxContext.CreateContextWorker(Document document,SemanticModel semanticModel,Int32 position,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery.CSharpSyntaxContextService.CreateContext(Document document,SemanticModel semanticModel,Int32 position,CancellationToken cancellationToken)
at async Microsoft.CodeAnalysis.Completion.Utilities.CreateSyntaxContextWithExistingSpeculativeModelAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CSharp.Completion.Providers.SpeculativeTCompletionProvider.ProvideCompletionsAsync()
at async Microsoft.CodeAnalysis.Completion.Providers.AbstractPreprocessorCompletionProvider.ProvideCompletionsAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformActionAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Shared.Extensions.DocumentExtensions.GetUnionItemsFromDocumentAndLinkedDocumentsAsyncT
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Completion.Providers.AbstractKeywordCompletionProvider`1.ProvideCompletionsAsyncTContext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformActionAsync()
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 13, 2024
@cston cston self-assigned this Nov 13, 2024
@cston
Copy link
Member

cston commented Nov 13, 2024

The exception occurs creating a SpeculativeSemanticModel and using a field reference within an accessor that does not use field. See #75398.

@jcouv jcouv added this to the 17.13 milestone Nov 14, 2024
@jcouv jcouv added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants