Skip to content

Commit

Permalink
Better error recovery from missing select or group clause. Fixes #3907.
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-safar committed Mar 19, 2012
1 parent 5dd3e25 commit fdd9ba8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
12 changes: 12 additions & 0 deletions mcs/errors/cs0742.cs
@@ -0,0 +1,12 @@
// CS0742: Unexpected symbol `;'. A query body must end with select or group clause
// Line: 10

using System.Linq;

class C
{
public static void Main ()
{
var q = from i in "abcd" where i;
}
}
26 changes: 19 additions & 7 deletions mcs/mcs/cs-parser.jay
Expand Up @@ -5751,7 +5751,7 @@ from_clause
;

query_body
: opt_query_body_clauses select_or_group_clause opt_query_continuation
: query_body_clauses select_or_group_clause opt_query_continuation
{
Linq.AQueryClause head = (Linq.AQueryClause)$2;

Expand All @@ -5766,7 +5766,24 @@ query_body

$$ = head;
}
| opt_query_body_clauses COMPLETE_COMPLETION
| select_or_group_clause opt_query_continuation
{
Linq.AQueryClause head = (Linq.AQueryClause)$2;

if ($1 != null) {
Linq.AQueryClause clause = (Linq.AQueryClause)$1;
clause.Tail.Next = head;
head = clause;
}

$$ = head;
}
| query_body_clauses COMPLETE_COMPLETION
| query_body_clauses error
{
report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
$$ = $1;
}
| error
{
Error_SyntaxError (yyToken);
Expand Down Expand Up @@ -5811,11 +5828,6 @@ select_or_group_clause
}
;

opt_query_body_clauses
: /* empty */
| query_body_clauses
;

query_body_clauses
: query_body_clause
| query_body_clauses query_body_clause
Expand Down
6 changes: 3 additions & 3 deletions mcs/tests/test-debug-19-ref.xml
Expand Up @@ -113,12 +113,12 @@
<entry il="0x22" row="35" file_ref="1" hidden="false" />
<entry il="0x2d" row="36" file_ref="1" hidden="false" />
<entry il="0x8b" row="37" file_ref="1" hidden="false" />
<entry il="0x380" row="38" file_ref="1" hidden="false" />
<entry il="0x490" row="39" file_ref="1" hidden="false" />
<entry il="0x3b1" row="38" file_ref="1" hidden="false" />
<entry il="0x4c1" row="39" file_ref="1" hidden="false" />
</sequencepoints>
<locals />
<scopes>
<entry index="0" start="0x22" end="0x470" />
<entry index="0" start="0x22" end="0x4a1" />
</scopes>
</method>
<method token="0x6000011">
Expand Down

0 comments on commit fdd9ba8

Please sign in to comment.