Bug 23268 – clamp no longer accepts shorts

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-07-22T20:03:16Z
Last change time
2022-08-31T09:10:58Z
Keywords
pull
Assigned to
No Owner
Creator
Temtaime

Comments

Comment #0 by temtaime — 2022-07-22T20:03:16Z
import std.algorithm.comparison; void main() { clamp(short.init, short.init, cast(const)short.init); } 2.067.1 to 2.098.1: Success and no output Since 2.099.1: Failure with output: ----- onlineapp.d(5): Error: none of the overloads of template `std.algorithm.comparison.clamp` are callable using argument types `!()(short, short, const(short))` /path/to/dmd.linux/dmd2/linux/bin64/../../src/phobos/std/algorithm/comparison.d(579): Candidate is: `clamp(T1, T2, T3)(T1 val, T2 lower, T3 upper)` with `T1 = short, T2 = short, T3 = const(short)` must satisfy the following constraint: ` is(typeof(val.lessThan(lower) ? lower : val.greaterThan(upper) ? upper : val) : T1)` -----
Comment #1 by razvan.nitu1305 — 2022-07-25T11:42:20Z
This issue is a manifestation of: *** This issue has been marked as a duplicate of issue 16235 ***
Comment #2 by razvan.nitu1305 — 2022-07-25T11:47:59Z
Additional information: a reduction of the phobos code that manifests in this case is: void main() { clamp(short.init, short.init, cast(const)short.init); } T1 clamp(T1, T2, T3)(T1 val, T2 lower, T3 upper) if (is(typeof(val < lower ? lower : val > upper ? upper : val) : T1)) { return val < lower ? lower : val > upper ? upper : val; } The problem is that the resulting type of the ternary expression is int instead of shared. It wrongfully casts the operands to int, as a result of 16235.
Comment #3 by razvan.nitu1305 — 2022-07-25T11:48:49Z
(In reply to RazvanN from comment #2) > Additional information: a reduction of the phobos code that manifests in > this case is: > > void main() > { > clamp(short.init, short.init, cast(const)short.init); > > } > > T1 clamp(T1, T2, T3)(T1 val, T2 lower, T3 upper) > if (is(typeof(val < lower ? lower : val > upper ? upper : val) : T1)) > { > return val < lower ? lower : val > upper ? upper : val; > } > > The problem is that the resulting type of the ternary expression is int > instead of shared. It wrongfully casts the operands to int, as a result of I meant: "is int instead of short" > 16235.
Comment #4 by temtaime — 2022-07-25T11:57:33Z
It worked two releases ago, it is a regression in phobos, no matter what are the causes. It breaks the code. Changes leaded to this regression must be reverted
Comment #5 by dlang-bot — 2022-08-24T11:43:21Z
@RazvanN7 created dlang/phobos pull request #8544 "Fix Issue 23268 - clamp no longer accepts shorts" fixing this issue: - Fix Issue 23268 - clamp no longer accepts shorts https://github.com/dlang/phobos/pull/8544
Comment #6 by dlang-bot — 2022-08-31T09:10:58Z
dlang/phobos pull request #8544 "Fix Issue 23268 - clamp no longer accepts shorts" was merged into master: - 43c5679784cb882e1e7e164aa60dead64dd859e0 by RazvanN7: Fix Issue 23268 - clamp no longer accepts shorts https://github.com/dlang/phobos/pull/8544