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
10 changes: 5 additions & 5 deletions src/System.Management.Automation/engine/parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3909,7 +3909,7 @@ private StatementAst ClassDefinitionRule(List<AttributeBaseAst> customAttributes
if (rCurly.Kind != TokenKind.RCurly)
{
UngetToken(rCurly);
ReportIncompleteInput(lastExtent, () => ParserStrings.MissingEndCurlyBrace);
ReportIncompleteInput(After(lCurly), rCurly.Extent, () => ParserStrings.MissingEndCurlyBrace);
}
else
{
Expand Down Expand Up @@ -4269,7 +4269,7 @@ private StatementAst EnumDefinitionRule(List<AttributeBaseAst> customAttributes,
if (rCurly.Kind != TokenKind.RCurly)
{
UngetToken(rCurly);
ReportIncompleteInput(After(lastExtent), () => ParserStrings.MissingEndCurlyBrace);
ReportIncompleteInput(After(lCurly), rCurly.Extent, () => ParserStrings.MissingEndCurlyBrace);
}

var startExtent = customAttributes != null && customAttributes.Count > 0
Expand Down Expand Up @@ -6344,8 +6344,8 @@ private ExpressionAst HashExpressionRule(Token atCurlyToken, bool parsingSchemaE
// Note - the error handling function inspects the error message body to extra the ParserStrings property name. It uses this value as the errorid.
var errorMessageExpression = parsingSchemaElement ?
(Expression<Func<string>>)(() => ParserStrings.IncompletePropertyAssignmentBlock)
: (Expression<Func<string>>)(() => ParserStrings.IncompleteHashLiteral);
ReportIncompleteInput(keyValuePairs.Any() ? After(keyValuePairs.Last().Item2) : After(atCurlyToken), rCurly.Extent, errorMessageExpression);
: (Expression<Func<string>>)(() => ParserStrings.MissingEndCurlyBrace);
ReportIncompleteInput(After(atCurlyToken), rCurly.Extent, errorMessageExpression);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it might degrade the quality of the error on:

@{
a =
}

or something like that - please try variants of this (for example: with and without the closing curly, with and without the =).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I tried to fix.

After that there is another question: Are NewLine and Semi terminators having the same rights? Compare:

@{
a = 
b =1
c =2
}


@{
a = ;
b =1;
c =2;
}

If we will fix this (require that the expression begin immediately after the equal on the same line) of cause it will be a breaking change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I don't recall explicitly supporting multiple statement terminators (you can have multiple semicolons as well) - so we shouldn't break anybody even though that's kinda broken.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear. Thanks!

endExtent = Before(rCurly);
}
else
Expand Down Expand Up @@ -6394,7 +6394,7 @@ private KeyValuePair GetKeyValuePair(bool parsingSchemaElement)
? (() => (ParserStrings.MissingEqualsInPropertyAssignmentBlock))
: (Expression<Func<string>>)(() => ParserStrings.MissingEqualsInHashLiteral);
ReportError(errorExtent, errorMessageExpression);
SyncOnError(true, TokenKind.RCurly, TokenKind.Semi, TokenKind.NewLine);
SyncOnError(false, TokenKind.RCurly, TokenKind.Semi, TokenKind.NewLine);
return new KeyValuePair(key, new ErrorStatementAst(errorExtent));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,6 @@ Possible matches are</value>
<data name="MissingExpressionInNamedArgument" xml:space="preserve">
<value>Missing statement after '=' in named argument.</value>
</data>
<data name="IncompleteHashLiteral" xml:space="preserve">
<value>The hash literal was incomplete.</value>
</data>
<data name="MissingPropertyTerminator" xml:space="preserve">
<value>Missing ';' or end-of-line in property definition.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Describe 'Positive Parse Properties Tests' -Tags "CI" {
Describe 'Negative Parsing Tests' -Tags "CI" {
ShouldBeParseError 'class' MissingNameAfterKeyword 5
ShouldBeParseError 'class foo' MissingTypeBody 9
ShouldBeParseError 'class foo {' MissingEndCurlyBrace 10
ShouldBeParseError 'class foo {' MissingEndCurlyBrace 11
ShouldBeParseError 'class foo { [int] }' IncompleteMemberDefinition 17
ShouldBeParseError 'class foo { $private: }' InvalidVariableReference 12
ShouldBeParseError 'class foo { [int]$global: }' InvalidVariableReference 17
Expand Down Expand Up @@ -307,6 +307,8 @@ Describe 'Negative Parsing Tests' -Tags "CI" {
ShouldBeParseError 'class C { static [int]$i; [void] foo() {$i = 10} }' MissingTypeInStaticPropertyAssignment 40

ShouldBeParseError 'class C : B' MissingTypeBody 11

ShouldBeParseError 'Class foo { q(){} w(){}' MissingEndCurlyBrace 11
}

Describe 'Negative methods Tests' -Tags "CI" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ New-Object Foo
It "report an error on incomplete using input" {
$err = Get-ParseResults "using module @{ModuleName = 'FooWithManifest'; FooWithManifest = 1." # missing closing bracket
$err.Count | Should Be 2
$err[0].ErrorId | Should Be 'IncompleteHashLiteral'
$err[0].ErrorId | Should Be 'MissingEndCurlyBrace'
$err[1].ErrorId | Should Be 'RequiresModuleInvalid'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Describe 'Basic enum errors' -Tags "CI" {
ShouldBeParseError 'enum foo' MissingTypeBody 8
ShouldBeParseError 'enum foo {' MissingEndCurlyBrace 10
ShouldBeParseError 'enum foo { x = }' ExpectedValueExpression 14
ShouldBeParseError 'enum foo { x =' ExpectedValueExpression,MissingEndCurlyBrace 14,14
ShouldBeParseError 'enum foo { x =' ExpectedValueExpression,MissingEndCurlyBrace 14,10
ShouldBeParseError 'enum foo {} enum foo {}' MemberAlreadyDefined 12
ShouldBeParseError 'enum foo { x; x }' MemberAlreadyDefined 14 -SkipAndCheckRuntimeError
ShouldBeParseError 'enum foo { X; x }' MemberAlreadyDefined 14 -SkipAndCheckRuntimeError
Expand All @@ -94,4 +94,5 @@ Describe 'Basic enum errors' -Tags "CI" {
ShouldBeParseError 'enum foo { e = [int]::MaxValue + 1 }' EnumeratorValueTooLarge 15 -SkipAndCheckRuntimeError
ShouldBeParseError 'enum foo { e = $foo }' EnumeratorValueMustBeConstant 15 -SkipAndCheckRuntimeError
ShouldBeParseError 'enum foo { e = "hello" }' CannotConvertValue 15 -SkipAndCheckRuntimeError
ShouldBeParseError 'enum foo { a;b;c;' MissingEndCurlyBrace 10
}
6 changes: 5 additions & 1 deletion test/powershell/Language/Parser/Parsing.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,8 @@ Describe 'expressions parsing' -Tags "CI" {
ShouldBeParseError '[ref][ref]$x' ReferenceNeedsToBeByItselfInTypeSequence 5
ShouldBeParseError '[int][ref]$x' ReferenceNeedsToBeLastTypeInTypeConversion 5
ShouldBeParseError '[int][ref]$x = 42' ReferenceNeedsToBeByItselfInTypeConstraint 5
}
}

Describe 'Hash Expression parsing' -Tags "CI" {
ShouldBeParseError '@{ a=1;b=2;c=3;' MissingEndCurlyBrace 2
}