Bug 23381 - "Function never returns" warning on function with yield return
Summary: "Function never returns" warning on function with yield return
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: 5.2
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: master
Assignee: Mike Krüger
Depends on:
Reported: 2014-09-25 14:59 UTC by Adam Kemp
Modified: 2017-08-22 06:15 UTC (History)
4 users (show)

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

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 Developer Community or GitHub 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 Adam Kemp 2014-09-25 14:59:21 UTC
The code analysis rule for "Function never returns" flags this method:

IEnumerable<int> AllInts()
    int i = 0;
    while (true)
        yield return i++;

I don't think it should flag methods that use "yield return". It's not uncommon to write methods with that kind of pattern. It's not actually a hang unless you try to enumerate all values (using something like ToList()).
Comment 1 Ram Chandra 2014-09-26 07:26:37 UTC
I have checked this issue but I am unable to reproduce this issue.

Steps I followed:

1. Create a console project.
2. Write the following method in Main class
3. Build the project.

When I build the project I am not getting the "Function never returns" warning.  However, when I hover cursor over the AllInts() method I am getting following error message:

Screencast: http://www.screencast.com/t/GzGjJD1p3Rms

Please let me know if I am missing something?

Environment Info:

Mac OS X 10.9.5
Xamarin Studio 5.5 (build 221)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
	Mono 3.10.0 ((detached/ac51002)
	GTK+ 2.24.23 (Raleigh theme)
	Package version: 310000016

=== Build Information ===

Release ID: 505000221
Git revision: 5593ae2759cc72daba96ad1a7bcf2b584a26e1cc
Build date: 2014-09-25 17:56:39-04
Xamarin addins: 9c609d1ca384863aafef4336d94b4b55d059d4ff
Comment 2 Adam Kemp 2014-09-26 10:44:07 UTC
This is a code analysis issue, not a build error. Notice the yellowish underline on the AllInts method name. That's the issue. If you hover over that it will tell you that the method never returns, which isn't accurate.
Comment 3 Ram Chandra 2014-10-07 11:52:00 UTC
I can reproduce the reported behavior as mentioned in comment 1. I am also getting a warning message on AllInts() method which is using "yield return". I’ll need confirmation from the developer if this is a bug. Leaving as NEW for now.

However, if I uncheck the "Enable source analysis of open file" option from "Xamarin Studio => Preferences... => Source Analysis ( Under Text Editor)" I am not getting any warning message when I hover over the "AllInts()" method.
Comment 4 Mike Krüger 2017-08-22 06:15:39 UTC
That quick fix is no longer part of MonoDevelop.