Bug 15936 – misleading error message about @disable where there is none

Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-04-17T18:00:31Z
Last change time
2022-11-07T10:50:20Z
Keywords
bootcamp, diagnostic
Assigned to
Mathias Lang
Creator
ag0aep6g

Comments

Comment #0 by ag0aep6g — 2016-04-17T18:00:31Z
Found by denizzzka who posted to D.learn: http://forum.dlang.org/post/[email protected] ---- struct Vector { void opAssign(Vector u) {} } struct RAMNode { Vector min; const bool isLeafNode = false; } void main() { RAMNode old_root; old_root = RAMNode.init; /* line 15 */ } ---- This code can't compile because isLeafNode is const. dmd gets confused by the opAssign, though, and prints: "test.d(15): Error: function test.RAMNode.opAssign is not callable because it is annotated with @disable". That's nonsense. There is no @disable anywhere. Without the opAssign the error message is ok: "test.d(15): Error: cannot modify struct old_root RAMNode with immutable members".
Comment #1 by mathias.lang — 2016-07-04T01:30:51Z
Yeah that's a compiler implementation detail. DMD tries to instantiate the code with gagging on, and on error, it just marks it as '@disable'd. For reference, the guilty code is https://github.com/dlang/dmd/blob/87ce5f860b9b8c4a9280e9d9d8643ac6a0df7bbd/src/clone.d#L319-L324
Comment #2 by razvan.nitu1305 — 2022-11-07T10:50:20Z
The error message has improved: test.d(15): Error: generated function `test.RAMNode.opAssign` cannot be used because it is annotated with `@disable` Since the error happens in generated code, the compiler does not output it. This makes sense as the user cannot directly modify generated code. So it just informs that the generated code has failed. Ideally, the compiler would point out an actionable item for the user to fix the breakage, however, currently the rudimentary error handling in dmd does not allow for that. Closing as WORKSFORME.