D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3127 - 'unreachable code' warning destroys delegate literal type inference
Summary: 'unreachable code' warning destroys delegate literal type inference
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2009-07-02 05:15 UTC by Don
Modified: 2014-04-18 09:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009-07-02 05:15:22 UTC
D1 and D2. Compile with -w.
===========
void bar(real delegate(real) f) {    }

void foo() {
    return;
    assert(0);
}

void main() {
    bar( (real x){ return x; });
}
===========
Output with DMD1.045:
C:\dev>dmd -w bug
warning - bug.d(5): Error: statement is not reachable
bug.d(9): Error: function bug.bar (real delegate(real)) does not match parameter
 types (int delegate(real x))
bug.d(9): Error: cannot implicitly convert expression (__dgliteral1) of type int
 delegate(real x) to real delegate(real)

On DMD2.030, the type is 'void' instead:
C:\dev>dmd -w bug
warning - bug.d(5): Error: statement is not reachable
bug.d(9): Error: function bug.bar (real delegate(real) f) does not match paramet
er types (void delegate(real x))
bug.d(9): Error: cannot implicitly convert expression (__dgliteral1) of type voi
d delegate(real x) to real delegate(real)
Comment 1 Jarrett Billingsley 2009-07-02 08:52:35 UTC
I'm not sure if this is valid, only because DMD treats warnings as errors, and the code wouldn't compile anyway even if it didn't spit out the bogus subsequent error.  I've had it spit out dumb semantic errors like this after other errors, and errors after the first are usually not to be trusted anyway..

It's kind of like how DMD sets the type of invalid expressions to 'int' and then marches on, giving you all sorts of dumb errors that don't actually mean anything.
Comment 2 Don 2009-07-03 01:09:08 UTC
>I'm not sure if this is valid, only because DMD treats warnings as errors, and
the code wouldn't compile anyway even if it didn't spit out the bogus
subsequent error.

If it were in the same function, I would agree. But in this case, I can't see _any_ reason for the error to propagate from one function to an unrelated one. It's an indication that something's wrong.
Comment 3 Don 2010-02-01 00:01:03 UTC
Fixed in D1 in DMD1.046, and in D2, sometime before D2.035.