未验证 提交 fad977f9 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Ensure we associate an error with all missing identifiers in the parser. (#44389)

* Ensure we associate an error with all missing identifiers in the parser.

* Fix test

* REstore original error
上级 fa2c7918
......@@ -6867,13 +6867,9 @@ private TypeSyntax ParseUnderlyingType(ParseTypeMode mode, NameOptions options =
return ParseFunctionPointerTypeSyntax();
}
var name = this.CreateMissingIdentifierName();
if (mode != ParseTypeMode.NewExpression)
{
return this.AddError(name, ErrorCode.ERR_TypeExpected);
}
return name;
return this.AddError(
this.CreateMissingIdentifierName(),
mode == ParseTypeMode.NewExpression ? ErrorCode.ERR_BadNewExpr : ErrorCode.ERR_TypeExpected);
}
#nullable enable
......@@ -11505,11 +11501,11 @@ private ExpressionSyntax ParseArrayOrObjectCreationExpression()
initializer = this.ParseObjectOrCollectionInitializer();
}
// we need one or the other
// we need one or the other. also, don't bother reporting this if we already complained about the new type.
if (argumentList == null && initializer == null)
{
argumentList = _syntaxFactory.ArgumentList(
this.EatToken(SyntaxKind.OpenParenToken, ErrorCode.ERR_BadNewExpr),
this.EatToken(SyntaxKind.OpenParenToken, ErrorCode.ERR_BadNewExpr, reportError: type?.ContainsDiagnostics == false),
default(SeparatedSyntaxList<ArgumentSyntax>),
SyntaxFactory.MissingToken(SyntaxKind.CloseParenToken));
}
......
......@@ -947,7 +947,7 @@ static void Main(string[] args)
Children(0)
";
var expectedDiagnostics = new DiagnosticDescription[] {
// CS1526: A new expression requires (), [], or {} after type
// file.cs(8,41): error CS1526: A new expression requires an argument list or (), [], or {} after type
// C1 /*<bind>*/c1 = new/*</bind>*/;
Diagnostic(ErrorCode.ERR_BadNewExpr, ";").WithLocation(8, 41)
};
......
......@@ -500,11 +500,8 @@ public void TestNewRefArray()
UsingStatement("new ref[];",
// (1,8): error CS1031: Type expected
// new ref[];
Diagnostic(ErrorCode.ERR_TypeExpected, "[").WithLocation(1, 8),
// (1,10): error CS1526: A new expression requires an argument list or (), [], or {} after type
// new ref[];
Diagnostic(ErrorCode.ERR_BadNewExpr, ";").WithLocation(1, 10)
);
Diagnostic(ErrorCode.ERR_TypeExpected, "[").WithLocation(1, 8));
N(SyntaxKind.ExpressionStatement);
{
N(SyntaxKind.ObjectCreationExpression);
......
......@@ -19,10 +19,9 @@ public class TargetTypedObjectCreationParsingTests : ParsingTests
public void TestNoRegressionOnNew()
{
UsingExpression("new", DefaultParseOptions,
// (1,4): error CS1526: A new expression requires (), [], or {} after type
// (1,4): error CS1526: A new expression requires an argument list or (), [], or {} after type
// new
Diagnostic(ErrorCode.ERR_BadNewExpr, "").WithLocation(1, 4)
);
Diagnostic(ErrorCode.ERR_BadNewExpr, "").WithLocation(1, 4));
N(SyntaxKind.ObjectCreationExpression);
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册