Recover from invalid yield return. Fixes #5064
authorMarek Safar <marek.safar@gmail.com>
Thu, 7 Jun 2012 13:26:27 +0000 (14:26 +0100)
committerMarek Safar <marek.safar@gmail.com>
Thu, 7 Jun 2012 13:26:27 +0000 (14:26 +0100)
mcs/mcs/cs-parser.jay

index 79892a2a0d3218c1d649c61cd6e506ce80bde089..2e4b2f81c54f8e1d6dbf6da29b57482e0c565f99 100644 (file)
@@ -5481,6 +5481,24 @@ yield_statement
                $$ = new Yield ((Expression) $3, lt.Location);
                lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
          }
+       | identifier_inside_body RETURN expression error
+         {
+               Error_SyntaxError (yyToken);
+
+               var lt = (Tokenizer.LocatedToken) $1;
+               string s = lt.Value;
+               if (s != "yield"){
+                       report.Error (1003, lt.Location, "; expected");
+               } else if ($3 == null) {
+                       report.Error (1627, GetLocation ($4), "Expression expected after yield return");
+               } else if (lang_version == LanguageVersion.ISO_1){
+                       FeatureIsNotAvailable (lt.Location, "iterators");
+               }
+               
+               current_block.Explicit.RegisterIteratorYield ();
+               $$ = new Yield ((Expression) $3, lt.Location);
+               lbag.AddStatement ($$, GetLocation ($2));
+         }
        | identifier_inside_body BREAK SEMICOLON
          {
                var lt = (Tokenizer.LocatedToken) $1;