Error: cannot return non-void from void function

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Nov 27 09:00:27 PST 2014


On Thu, 27 Nov 2014 13:07:58 +0000
Suliman via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:

> Full function look like this:
> 
> auto parseConfig()
> {
> 	auto config = Ini.Parse(getcwd ~ "\\" ~ "config.ini");
> 	string txtlinks = getcwd ~ "\\" ~ config.getKey("input_links");
> 	if(!exists(txtlinks))
> 	{
> 		writeln("Can't find input file with list of links.");
> 		return;
> 	}
> 	auto lines = File(txtlinks, "r").byLine;
> 	return lines;
> 
> }
ah, that's it! as spec says, D determines function return value from
the first 'return' statement it seen. in your case this is `return;`,
so function return type is determined to be `void`.

if you doing `auto` functions, try to arrange your code so the first
`return` returning the actual value.

besides, your code is wrong anyway, 'cause you can't have function that
returns both "nothing" and "something". your first `return;` should
either return something, or must be changed to throwing some exception.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141127/1635d2b0/attachment.sig>


More information about the Digitalmars-d-learn mailing list