Bug 5195 - [AST] Error that causes method block not inserted.
Summary: [AST] Error that causes method block not inserted.
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2012-05-20 21:28 UTC by Neal
Modified: 2013-03-24 06:40 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

What I did. (135.18 KB, video/mpeg)
2012-05-22 02:23 UTC, Mike Krüger

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Neal 2012-05-20 21:28:16 UTC
I'm typing a ternary statement such as that below and when pressing : I get a popup/intellisense list of namespaces!

var foo = MyValue == 0 ? "Something" :
Comment 1 Mike Krüger 2012-05-21 07:05:53 UTC
Can't reproduce that one - I would need a more complex use case for that one to verify.
Comment 2 Neal 2012-05-21 22:04:38 UTC
Try the following:

		private static string DoSomething(int dur)
			return dur == 12 ? "Hello"

Type : after "Hello" and then space and you should see the issue.
Comment 3 Mike Krüger 2012-05-22 02:23:04 UTC
Created attachment 1937 [details]
What I did.

I can't get it - see the video.
What do I wrong ?
Comment 5 Neal 2012-05-22 09:28:43 UTC
screencast provided
Comment 7 Mike Krüger 2012-05-23 03:39:11 UTC
Method block not inserted in the AST for error:
class MainClass
   public string Test ()
        return true ? "Hello" : 

Comment 8 Marek Safar 2013-03-22 09:59:44 UTC
Another jay issue where error recovery fails completely when there are not enough tokens. In this case Test method is missing completely
Comment 9 Miguel de Icaza [MSFT] 2013-03-22 18:02:30 UTC
I have a vague memory of documenting how to recover from parser errors like this, but right now, I cant remember where it is.   So I looked at some similar fixes in the past.

I think I got it right.

Can you guys try this?

(Oh, and remove the WriteLines)

diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay
index 9330a3e..f9a0029 100644
--- a/mcs/mcs/cs-parser.jay
+++ b/mcs/mcs/cs-parser.jay
@@ -4329,6 +4329,7 @@ conditional_expression
 		Error_SyntaxError (yyToken);
 		$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
+		Console.WriteLine ("HERE");
 	| null_coalescing_expression INTERR expression COLON error
@@ -4337,6 +4338,16 @@ conditional_expression
 		$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
 		lbag.AddLocation ($$, GetLocation ($4));
+	| null_coalescing_expression INTERR expression COLON CLOSE_BRACE
+	  {
+		Error_SyntaxError (Token.CLOSE_BRACE);
+		Console.WriteLine ("Hawt");
+		$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
+		lbag.AddLocation ($$, GetLocation ($4));
+		Console.WriteLine ("Departing");
+		lexer.putback ('}');
+	  }
Comment 10 Marek Safar 2013-03-24 06:40:54 UTC
Patch applied