dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.02k stars 4.03k forks source link

Pressing ENTER after invalid LINQ expression results in dialog with "Unexpected Null" #5495

Closed DustinCampbell closed 9 years ago

DustinCampbell commented 9 years ago
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
    class AutomapperConfig
    {
        public static IEnumerable<string> ConfigureMappings(string name)
        {
            List<User> anEntireSlewOfItems = new List<User>();
            List<UserViewModel> viewModels = new List<UserViewModel>();

            var items = (from m in anEntireSlewOfItems into man
             join at in viewModels on m.id equals at.id
             join c in viewModels on m.name equals c.name
             join ct in viewModels on m.phonenumber equals ct.phonenumber
             where m.id == 1 &&
                 m.name == name
             select new { M = true, I = at, AT = at }).ToList();
            //Mapper.CreateMap<User, UserViewModel>()
            //    .ForMember(t => t.)
        }
    }

    class User
    {
        public int id { get; set; }
        public string name { get; set; }
        public int phonenumber { get; set; }
    }

    class UserViewModel
    {
        public int id { get; set; }
        public string name { get; set; }
        public int phonenumber { get; set; }
    }
}

Move caret after "into man" and press Enter.

DustinCampbell commented 9 years ago

Call stack is:

System.InvalidOperationException: Unexpected Null
   at Roslyn.Utilities.Contract.Fail(String message) in D:\Roslyn\Open\src\Workspaces\Core\Portable\Utilities\Contract.cs:line 106
   at Roslyn.Utilities.Contract.ThrowIfNull[T](T value, String message) in D:\Roslyn\Open\src\Workspaces\Core\Portable\Utilities\Contract.cs:line 73
   at Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation.CSharpIndentationService.Indenter.GetIndentationForQueryExpression(SyntaxToken token) in D:\Roslyn\Open\src\EditorFeatures\CSharp\Formatting\Indentation\CSharpIndentationService.Indenter.cs:line 366
   at Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation.CSharpIndentationService.Indenter.GetDefaultIndentationFromToken(SyntaxToken token) in D:\Roslyn\Open\src\EditorFeatures\CSharp\Formatting\Indentation\CSharpIndentationService.Indenter.cs:line 356
   at Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation.CSharpIndentationService.Indenter.GetIndentationBasedOnToken(SyntaxToken token) in D:\Roslyn\Open\src\EditorFeatures\CSharp\Formatting\Indentation\CSharpIndentationService.Indenter.cs:line 278
   at Microsoft.CodeAnalysis.Editor.CSharp.Formatting.Indentation.CSharpIndentationService.Indenter.GetDesiredIndentation() in D:\Roslyn\Open\src\EditorFeatures\CSharp\Formatting\Indentation\CSharpIndentationService.Indenter.cs:line 70
   at Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent.AbstractIndentationService.GetDesiredIndentationAsync(Document document, Int32 lineNumber, CancellationToken cancellationToken) in D:\Roslyn\Open\src\EditorFeatures\Core\Implementation\SmartIndent\AbstractIndentationService.cs:line 55
   at Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent.SmartIndent.GetDesiredIndentation(ITextSnapshotLine lineToBeIndented, CancellationToken cancellationToken) in D:\Roslyn\Open\src\EditorFeatures\Core\Implementation\SmartIndent\SmartIndent.cs:line 61
   at Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent.SmartIndent.GetDesiredIndentation(ITextSnapshotLine line) in D:\Roslyn\Open\src\EditorFeatures\Core\Implementation\SmartIndent\SmartIndent.cs:line 33
   at Microsoft.VisualStudio.Text.Editor.Implementation.SmartIndentationService.GetDesiredIndentation(ITextView textView, ITextSnapshotLine line)
   at Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.PositionCaretWithSmartIndent(Boolean useOnlyVirtualSpace, Boolean extendSelection)
   at Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.<InsertNewLine>b__62_0()
   at Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.ExecuteAction(String undoText, Func`1 action, SelectionUpdate preserveCaretAndSelection, Boolean ensureVisible)
   at Microsoft.VisualStudio.Text.Operations.Implementation.EditorOperations.InsertNewLine()
   at Roslyn.Editor.TestApp.UI.Editor.EditorCommandTarget.Execute(CommandArgs args, Action nextHandler) in D:\Roslyn\Closed\Hosting\EditorTestApp\UI\Commands\CommandTargets\EditorCommandTarget.cs:line 77
   at Roslyn.Editor.TestApp.UI.Editor.GuidCommandTarget.Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget.Exec(Guid& pguidCmdGroup, UInt32 commandId, UInt32 cmdExecOpt, IntPtr pvaIn, IntPtr pvaOut) in D:\Roslyn\Closed\Hosting\EditorTestApp\UI\Commands\CommandTargets\GuidCommandTarget.cs:line 275
   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(Guid& pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.Exec(Guid& pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
   at Microsoft.VisualStudio.Editor.Implementation.BraceCompletionCommandFilter.Exec(Guid& pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(Guid& pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.Exec(Guid& pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
   at Microsoft.VisualStudio.Editor.Implementation.IntellisenseCommandFilter.Exec(Guid& pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(Guid& pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
   at Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(Guid& pguidCmdGroup, UInt32 nCmdID, UInt32 nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
DustinCampbell commented 9 years ago

Essentially the problem here is that there is a continuation but no group or select. This triggers a contract failure but it should probably just fall back to default indentation.