method has no return statement with switch

crimaniak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 6 16:21:51 PST 2015


Hi!

I have the error message:
source/url.cache.d(20,16): Error: function 
url.Cache.UrlCache.doRequest has no return statement, but is 
expected to return a value of type string

Inserting dummy return statement doesn't help. final switch / 
switch with default - no matter.

As I understand compiler must detect when end of function is 
unreachable (and in fact it detects it - see comment about return 
""; line) and do not try to check for return value. Is this my or 
compiler's error here?

>dmd --version
DMD64 D Compiler v2.069.0
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright


[code]
module url.Cache;

import std.conv;
import core.exception;
import mysql.d;
import std.digest.md;
import std.net.curl;

enum Method { GET="GET", POST="POST" }

class UrlCache
{
// ...
	public string doRealRequest(string url, Method method)
	{
		final switch(method)
		{
			case Method.GET:
				return std.net.curl.get!AutoProtocol(url).text;
			case Method.POST:
				return std.net.curl.post(url, []).text;
		}
		// return ""; // produces 'statement is not reachable' warning, 
don't fix the problem
	}
// ...	
}
[/code]



More information about the Digitalmars-d-learn mailing list