Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3193,6 +3193,11 @@ public override BoundNode VisitSequencePointWithSpan(BoundSequencePointWithSpan
return null;
}

public override BoundNode VisitModuleCancellationTokenExpression(ModuleCancellationTokenExpression node)
{
return null;
}

public override BoundNode VisitStatementList(BoundStatementList node)
{
return VisitStatementListWorker(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2783,4 +2783,28 @@ void G<S>(T a, S b) {}
var verifier = CompileAndVerify(source);
AssertNotInstrumentedWithTokenLoad(verifier, "C<T>.G<S>(T, S, System.Threading.CancellationToken)");
}

[Fact]
public void FlowPass()
{
var source = """
using System.Threading;
using System.Collections.Generic;

class C
{
IEnumerable<int> F()
{
var x = G() as string;
yield return (x != null) ? 1 : 0;
}

object G(CancellationToken token = default)
=> "";
}
""";

// definite assignment flow pass doesn't fail
CompileAndVerify(source).VerifyDiagnostics();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,51 @@ static ISymbol F(ISymbol s)
$" at <Select Iterator>()" + Environment.NewLine,
Regex.Replace(exception.StackTrace.JoinText(), @"System\.Linq\.Enumerable\..*\.MoveNext", "<Select Iterator>"));
}

/// <summary>
/// Checks that flow pass handles semantic query code end-to-end
/// (specifically, module cancellation and stack overflow instrumentation).
/// </summary>
[ConditionalFact(typeof(CoreClrOnly))]
public async Task FlowPass()
{
using var workspace = TestWorkspace.Create(DefaultWorkspaceXml, composition: FeaturesTestCompositions.Features);

var solution = workspace.CurrentSolution;

var service = solution.Services.GetRequiredLanguageService<ISemanticSearchService>(LanguageNames.CSharp);

var query = """
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

static IEnumerable<ISymbol> Find(IMethodSymbol method)
{
var syntaxReference = method.DeclaringSyntaxReferences.FirstOrDefault();
if (syntaxReference != null)
{
while (true)
{
var syntaxNode = syntaxReference.GetSyntax() as MethodDeclarationSyntax;
if (syntaxNode != null)
{
yield return method;
}

break;
}
}
}
""";

var results = new List<DefinitionItem>();
var observer = new MockSemanticSearchResultsObserver() { OnDefinitionFoundImpl = results.Add };
var traceSource = new TraceSource("test");

var options = workspace.GlobalOptions.GetClassificationOptionsProvider();
var result = await service.ExecuteQueryAsync(solution, query, s_referenceAssembliesDir, observer, options, traceSource, CancellationToken.None);

Assert.Null(result.ErrorMessage);
AssertEx.Equal(["void C.VisibleMethod(int)"], results.Select(Inspect));
}
}
Loading