Bug 14506 – Wrong floating point type inferred for function with auto return type

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-26T21:09:35Z
Last change time
2024-12-13T18:42:35Z
Assigned to
No Owner
Creator
Meta
Moved to GitHub: dmd#18984 →

Comments

Comment #0 by monkeyworks12 — 2015-04-26T21:09:35Z
import std.random; auto test(int n) { if (n >= 0 && n < 33) { return int(0); } else if (n >= 33 && n < 66) { return float(0); } else { return real(0); } } void main() { auto n = uniform(0, 100); auto res = test(n); //typeof(res) should be inferred as real assert(is(typeof(res) == float)); } Another example from Ali Çehreli: import std.traits; import std.typetuple; import std.format; auto foo(A, B)(int n) { if (n) { return A(0); } else { return B(0); } } void main() { alias types = TypeTuple!(float, double, real); foreach (A; types) { foreach (B; types) { alias ReturnType = typeof(foo!(A, B)(0)); pragma(msg, format("%s %s -> %s%s", A.stringof, B.stringof, ReturnType.stringof, (is (ReturnType == CommonType!(A, B)) ? "" : " <-- BUG"))); } } } Output: float float -> float float double -> float <-- BUG float real -> float <-- BUG double float -> double double double -> double double real -> double <-- BUG real float -> real real double -> real real real -> real
Comment #1 by monkeyworks12 — 2015-12-27T02:41:05Z
With version 2.069.1 of DMD my case now passes, but Ali's remains the same.
Comment #2 by robert.schadek — 2024-12-13T18:42:35Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18984 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB