Bug 18287 – [Reg 2.078.1] several std.math functions no longer work with alias this

Status
REOPENED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-01-23T10:11:50Z
Last change time
2024-12-01T16:32:09Z
Assigned to
No Owner
Creator
John Colvin
Moved to GitHub: phobos#9738 →

Comments

Comment #0 by john.loughran.colvin — 2018-01-23T10:11:50Z
https://github.com/dlang/phobos/pull/6040/files changed several functions (signbit, isFinite, isNormal, isSubnormal, sign, nextAfter and approxEqual to enforce type matching, meaning that all alias-this types no longer work with them
Comment #1 by hsteoh — 2018-01-23T19:21:22Z
Has signbit() ever worked with alias this types? I tried commenting out the new sig constraint of signbit(), but this code still fails to compile on git master: -------- struct Proxy { double f; alias f this; } auto p = Proxy(1.61803); auto sign = signbit(p); -------- The compiler says: --------- std/math.d(267): Error: cannot implicitly convert expression 4.50360e+15 of type double to Proxy std/math.d(5762): Error: template instance std.math.floatTraits!(Proxy) error instantiating std/math.d(5806): instantiated from here: signbit!(Proxy) -------- This is caused by signbit() attempting to instantiate floatTraits with Proxy, but floatTraits does not take alias this into account. (Not that it *shouldn't* work with alias this, but just that it doesn't seem to have worked before. Or perhaps that only broke after floatTraits was introduced?)
Comment #2 by edi33416 — 2018-12-17T11:41:04Z
So, what is the general consent here? Should this work with `alias this`, or should we close as `WONTFIX`? IMHO, this is more likely a compiler bug, as the template constraint should also be checked on `alias this`, if one is present.
Comment #3 by Ajieskola — 2021-11-01T16:47:06Z
Someone marked this issue as resolved, but provided no reasoning. This won't do - I'm reopening until there's a verifiable fix.
Comment #4 by john.loughran.colvin — 2021-11-02T21:02:35Z
(In reply to hsteoh from comment #1) > Has signbit() ever worked with alias this types? I tried commenting out the > new sig constraint of signbit(), but this code still fails to compile on git > master: > > -------- > struct Proxy { > double f; > alias f this; > } > auto p = Proxy(1.61803); > auto sign = signbit(p); > -------- > > The compiler says: > --------- > std/math.d(267): Error: cannot implicitly convert expression 4.50360e+15 of > type double to Proxy > std/math.d(5762): Error: template instance std.math.floatTraits!(Proxy) > error instantiating > std/math.d(5806): instantiated from here: signbit!(Proxy) > -------- > > This is caused by signbit() attempting to instantiate floatTraits with > Proxy, but floatTraits does not take alias this into account. > > (Not that it *shouldn't* work with alias this, but just that it doesn't seem > to have worked before. Or perhaps that only broke after floatTraits was > introduced?) It did work before dmd 2.066.0 struct Proxy { double f; alias f this; } void main(){ import std.math; auto p = Proxy(1.61803); auto sign = signbit(p); } Up to 2.065.0: Success and no output https://run.dlang.io/is/WHDPrI
Comment #5 by robert.schadek — 2024-12-01T16:32:09Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9738 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB