Bug 3127 – 'unreachable code' warning destroys delegate literal type inference

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Windows
Creation time
2009-07-02T05:15:00Z
Last change time
2014-04-18T09:12:05Z
Keywords
diagnostic
Assigned to
nobody
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2009-07-02T05:15:22Z
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 by jarrett.billingsley — 2009-07-02T08:52:35Z
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 by clugdbug — 2009-07-03T01:09:08Z
>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 by clugdbug — 2010-02-01T00:01:03Z
Fixed in D1 in DMD1.046, and in D2, sometime before D2.035.