Skip to content

Commit

Permalink
Fix fall through
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Oct 5, 2021
1 parent 6fd59f1 commit 18263f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class Program
static void Main()
{
int x = 2;
Bar(x < x, (x > (1 + 2)));
Bar(x < x, (x > 1 + 2));
}
static void Bar(object a, object b)
Expand Down Expand Up @@ -670,7 +670,7 @@ class Program
static void Main()
{
int x = 2;
var z = new[] { x < x, (x > (1 + 2)) };
var z = new[] { x < x, x > 1 + 2 };
}
}");
}
Expand Down Expand Up @@ -2131,7 +2131,7 @@ class C
static void Main()
{
Action<string> g = null;
var h = Goo + g;
var h = (Goo<string>) + g;
}
static void Goo<T>(T y) { }
Expand Down Expand Up @@ -2368,7 +2368,7 @@ class C
{
static void Main()
{
Goo((Action<int[]>)(x => { x[1] = x[0]; }));
Goo(x => { x[1] = (int)x[0]; });
}
static void Goo(Action<int[]> x) { }
Expand Down Expand Up @@ -2847,7 +2847,7 @@ class C
{
static void M()
{
Goo(() => { return 42; }, (Func<long>)(() => { return 42; }));
Goo(() => { return 42; }, () => { return (long)42; });
}
static void Goo(Func<int> x, Func<int> y) { }
Expand Down Expand Up @@ -3043,10 +3043,10 @@ class C
static void Main()
{
Goo((Action<string>)(x =>
Goo(x =>
{
var y = x;
}));
var y = (string)x;
});
}
}");
}
Expand Down Expand Up @@ -3378,7 +3378,7 @@ static class C
static void Main()
{
Outer(y => Inner(x => { Action a = () => x.GetType(); }, y), null);
Outer(y => Inner(x => { Action a = () => ((string)x).GetType(); }, y), null);
}
}
");
Expand Down Expand Up @@ -5118,8 +5118,8 @@ class C
void M()
{
{|Warning:(new C()).P = 1|};
var c2 = (new C());
{|Warning:new C().P = 1|};
var c2 = new C();
}
}");
}
Expand Down Expand Up @@ -5345,7 +5345,7 @@ public async Task TopLevelStatement()

var expected = @"
int val = 0;
global::System.Console.WriteLine(val + 1);
System.Console.WriteLine(val + 1);
";

// Global statements in regular code are local variables, so Inline Temporary works. Script code is not
Expand All @@ -5370,7 +5370,7 @@ public async Task TopLevelStatement_InScope()
@"
{
int val = 0;
global::System.Console.WriteLine(val + 1);
System.Console.WriteLine(val + 1);
}
",
TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp9));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private class ReferenceRewriter : CSharpSyntaxRewriter
_cancellationToken.ThrowIfCancellationRequested();

if (_conflictReferences.Contains(node))
node.Update(node.Identifier.WithAdditionalAnnotations(CreateConflictAnnotation()));
return node.Update(node.Identifier.WithAdditionalAnnotations(CreateConflictAnnotation()));

if (_nonConflictReferences.Contains(node))
return _expressionToInline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ private static SyntaxNode RemoveDeclaratorFromScope(VariableDeclaratorSyntax var
}
else
{
if (localSymbol.Type.ContainsAnonymousType() || localSymbol.Type is IErrorTypeSymbol { Name: null or "" })
return expression;

return expression.Cast(localSymbol.Type);
}

Expand Down

0 comments on commit 18263f7

Please sign in to comment.