Bug 22782 – [dip1000] address of ref can be assigned to non-scope parameter

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-02-16T19:45:33Z
Last change time
2022-02-18T13:59:12Z
Keywords
pull, safe, Vision
Assigned to
No Owner
Creator
Ate Eskola

Comments

Comment #0 by Ajieskola — 2022-02-16T19:45:33Z
------ struct DontDoThis { immutable char[12] content; @safe this(char ch) { content[] = ch; throw new Exception(content[]); } } void main() @safe { import std.stdio; DontDoThis('a'); } ------ Prints a garbage error message. Compiled with -preview=dip1000, using latest master.
Comment #1 by Ajieskola — 2022-02-16T19:50:17Z
Also triggered with an assertion: ------ struct DontDoThis { immutable char[12] content; @safe this(char ch) { content[] = ch; assert(0, content[]); } } void main() @safe { DontDoThis('a'); } ------
Comment #2 by dkorpel — 2022-02-16T20:42:28Z
This isn't about constructors or exceptions, it reduces to: ``` @safe: void fun(ref int x) { int* scopePtr = &x; // correctly inferred scope escape(scopePtr); // correctly rejected escape(&x); // accepts invalid } int* gPtr; void escape(int* ptr) { gPtr = ptr; } ``` My fix for issue 12812 (https://github.com/dlang/dmd/pull/12812) was not tested thoroughly enough, I will look into it.
Comment #3 by dkorpel — 2022-02-16T20:43:57Z
(In reply to Dennis from comment #2) > My fix for issue 12812 Correction: issue 20245
Comment #4 by dlang-bot — 2022-02-16T20:57:37Z
@dkorpel created dlang/dmd pull request #13672 "Fix Issue 22782 - address of ref can be assigned to non-scope parameter" fixing this issue: - Fix Issue 22782 - address of ref can be assigned to non-scope parameter https://github.com/dlang/dmd/pull/13672
Comment #5 by dkorpel — 2022-02-16T21:13:57Z
*** Issue 22783 has been marked as a duplicate of this issue. ***
Comment #6 by dlang-bot — 2022-02-18T13:59:12Z
dlang/dmd pull request #13672 "Fix Issue 22782 - address of ref can be assigned to non-scope parameter" was merged into master: - b533cf65ff9467a147fc65390ae2e0363e2ce358 by dkorpel: Fix Issue 22782 - address of ref can be assigned to non-scope parameter https://github.com/dlang/dmd/pull/13672