D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20383 - [REG 2.084.z] illegal conversion from int[] to ubyte[] is accepted
Summary: [REG 2.084.z] illegal conversion from int[] to ubyte[] is accepted
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: ice, pull, wrong-code
Depends on:
Blocks:
 
Reported: 2019-11-11 00:58 UTC by basile-z
Modified: 2019-12-18 21:34 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 basile-z 2019-11-11 00:58:46 UTC
This code compiles since 2.084.(1/0?) but it is illegal:

---
ubyte[1] ice(ubyte[1] data)
{
    ubyte[1] result = data[] & [42];
    return result;
}

void main()
{
    assert (ice([1]) == [0]);
} 
---

But fails at runtime with a range violation.
Previously it was rejected with the message:

---
Error: cannot implicitly convert expression `data[] & [42]` of type `int[]` to `ubyte[]`
---

Which should still be the case, unless 42 is cast to ubyte or constructed as ubyte(42).


The backend has a protection to detect the illegal element but it's not written correctly. It uses the style `assert(!condition)` instead of `if (condition) assert(0);` and because of that an ICE does not happen when DMD is compiled with -release. See `dmd.e2ir.toElemBin(BinExp be, int op)`
Comment 1 Walter Bright 2019-12-07 07:01:30 UTC
It does work with DMD 2.074. Anyone want to do a bisect to see which PR broke it?
Comment 2 Dlang Bot 2019-12-07 08:24:32 UTC
@WalterBright created dlang/dmd pull request #10642 "fix Issue 20383 - [REG 2.084.z] illegal conversion from int[] to ubyt…" fixing this issue:

- fix Issue 20383 - [REG 2.084.z] illegal conversion from int[] to ubyte[] is accepted

https://github.com/dlang/dmd/pull/10642
Comment 3 Dlang Bot 2019-12-18 21:34:54 UTC
dlang/dmd pull request #10642 "fix Issue 20383 - [REG 2.084.z] illegal conversion from int[] to ubyt…" was merged into stable:

- ebeb86e36e2bdf6fbee065bed313cfc3cbdedb0d by Walter Bright:
  fix Issue 20383 - [REG 2.084.z] illegal conversion from int[] to ubyte[] is accepted

https://github.com/dlang/dmd/pull/10642