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

Verify semantic model on suppression operator #38756

Merged
merged 2 commits into from
Sep 21, 2019
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
23 changes: 23 additions & 0 deletions src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5518,5 +5518,28 @@ static void Main()
var compilation = CreateCompilation(source, options: TestOptions.ReleaseExe);
base.CompileAndVerify(compilation, expectedOutput: expectedOutput);
}

[Fact, WorkItem(38543, "https://github.com/dotnet/roslyn/issues/38543")]
public void AsyncLambdaWithAwaitedTasksInTernary()
{
var source = @"
using System;
using System.Threading.Tasks;

class Program
{
static Task M(bool b) => M2(async () =>
b ? await Task.Delay(1) : await Task.Delay(2));

static T M2<T>(Func<T> f) => f();
}";
// The diagnostic message isn't great, but it is correct that we report an error
var c = CreateCompilation(source, options: TestOptions.DebugDll);
c.VerifyDiagnostics(
// (8,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
// b ? await Task.Delay(1) : await Task.Delay(2));
Diagnostic(ErrorCode.ERR_IllegalStatement, "b ? await Task.Delay(1) : await Task.Delay(2)").WithLocation(8, 9)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1634,12 +1634,7 @@ public static void M(string x, string? y)

var suppression = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().First();
Assert.Equal(@"$""hello ""!", suppression.ToString());

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

// should be IFormattable twice
//VerifyTypeInfo(model, suppression, "System.String", "System.IFormattable");
VerifyTypeInfo(model, suppression, "System.String", "System.IFormattable");

var interpolated = suppression.Operand;
Assert.Equal(@"$""hello """, interpolated.ToString());
Expand Down Expand Up @@ -1671,13 +1666,10 @@ public static void M(string x, string? y)
var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

var suppression = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().First();

Assert.Equal(@"$""hello ""!", suppression.ToString());
//VerifyTypeInfo(model, suppression, "System.String", "System.String");
VerifyTypeInfo(model, suppression, "System.String", "System.String");

var interpolated = suppression.Operand;
Assert.Equal(@"$""hello """, interpolated.ToString());
Expand Down Expand Up @@ -1728,11 +1720,7 @@ static void M()
var model = comp.GetSemanticModel(tree);

var suppression = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().Single();

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

//VerifyTypeInfo(model, suppression, "System.String", "System.String");
VerifyTypeInfo(model, suppression, "System.String", "System.String");

var literal = suppression.Operand;
VerifyTypeInfo(model, literal, "System.String", "System.String");
Expand All @@ -1759,11 +1747,8 @@ static void M()
var model = comp.GetSemanticModel(tree);
var suppressions = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().ToArray();

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

//Assert.Equal(3, model.GetConstantValue(suppressions[0]).Value);
//Assert.Null(model.GetConstantValue(suppressions[1]).Value);
Assert.Equal(3, model.GetConstantValue(suppressions[0]).Value);
Assert.Null(model.GetConstantValue(suppressions[1]).Value);
}

[Fact]
Expand All @@ -1787,9 +1772,6 @@ void M(string s, string? s2, C<string> c, C<string?> c2)
var model = comp.GetSemanticModel(tree);
var suppressions = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().ToArray();

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

var s = model.GetTypeInfo(suppressions[0]);
Assert.Equal("System.String", s.Type.ToTestDisplayString());
Assert.Equal("System.String", s.ConvertedType.ToTestDisplayString());
Expand Down Expand Up @@ -1859,13 +1841,9 @@ static void Main()
var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

// unepxected answer from semantic model
var suppression = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().First();
Assert.Equal("M2!", suppression.ToString());
//VerifyTypeInfo(model, suppression, null, "C.Copier");
VerifyTypeInfo(model, suppression, null, "C.Copier");

var methodGroup = suppression.Operand;
VerifyTypeInfo(model, methodGroup, null, "C.Copier");
Expand Down Expand Up @@ -2170,15 +2148,12 @@ static void Main()
);
CompileAndVerify(comp);

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);

var suppression = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().Single();
Assert.Equal("(string? x) => { return null; }!", suppression.ToString());
//VerifyTypeInfo(model, suppression, null, "C.Copier");
VerifyTypeInfo(model, suppression, null, "C.Copier");

var lambda = suppression.Operand;
Assert.Equal("(string? x) => { return null; }", lambda.ToString());
Expand Down Expand Up @@ -2215,12 +2190,9 @@ static void M()
var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

var suppression = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().Single();
Assert.Equal("(string? x) => { return null; }!", suppression.ToString());
//VerifyTypeInfo(model, suppression, "C.Copier", "C.Copier");
VerifyTypeInfo(model, suppression, null, "C.Copier");

var lambda = suppression.Operand;
Assert.Equal("(string? x) => { return null; }", lambda.ToString());
Expand Down Expand Up @@ -2253,10 +2225,7 @@ static void Main()
var suppression = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().Single();
Assert.Equal("(string x) => { return string.Empty; }!", suppression.ToString());

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

//VerifyTypeInfo(model, suppression, null, "C.Copier");
VerifyTypeInfo(model, suppression, null, "C.Copier");

var lambda = suppression.Operand;
Assert.Equal("(string x) => { return string.Empty; }", lambda.ToString());
Expand Down Expand Up @@ -2287,12 +2256,9 @@ static void Main()
var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

var suppression = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().Single();
Assert.Equal("(string x) => { return string.Empty; }!", suppression.ToString());
//VerifyTypeInfo(model, suppression, "C.Copier", "C.Copier");
VerifyTypeInfo(model, suppression, null, "C.Copier");

var lambda = suppression.Operand;
Assert.Equal("(string x) => { return string.Empty; }", lambda.ToString());
Expand Down Expand Up @@ -2386,8 +2352,12 @@ static void Main()
Diagnostic(ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate, "M2").WithArguments("x", "string C.M2(string x)", "System.Func<string?, string?>").WithLocation(14, 47));
CompileAndVerify(comp);

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661
var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);
var suppression = tree.GetRoot().DescendantNodes().OfType<PostfixUnaryExpressionSyntax>().First();
Assert.Equal(@"(string? x) => { return null; }!", suppression.ToString());
VerifyTypeInfo(model, suppression, null, "System.Func<System.String, System.String>");
VerifyTypeInfo(model, suppression.Operand, null, "System.Func<System.String, System.String>");
}

[Fact, WorkItem(31370, "https://github.com/dotnet/roslyn/issues/31370")]
Expand Down Expand Up @@ -23539,9 +23509,6 @@ public void Main(string? key)
}
" }, options: WithNonNullTypesTrue());

// Need to verify the semantic model
// Tracked by https://github.com/dotnet/roslyn/issues/32661

VerifyVarLocal(c, "string?");
c.VerifyTypes();
c.VerifyDiagnostics();
Expand Down