Bug 19210 – Poor error message for `return` function parameter that is not `ref`

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-08-31T07:51:30Z
Last change time
2020-09-03T02:32:34Z
Keywords
pull, safe
Assigned to
No Owner
Creator
Mike Franklin

Comments

Comment #0 by slavo5150 — 2018-08-31T07:51:30Z
@safe: ref int identity(return ref int x) { return x; } ref int fun(return int x) { return identity(x); //Error: returning identity(x) escapes a reference to parameter x, perhaps annotate with return } void main() { int i; int j = fun(i); } $ dmd -dip25 main.d https://run.dlang.io/is/lvvRUR The problem is that `x`, in function `fun` is already annotated with `return`, so the error message doesn't make sense. I believe there should be an error message emitted disallowing `return` on parameters that are not `ref` or `out`, but I'm not sure
Comment #1 by dlang-bot — 2020-07-30T08:55:49Z
@Geod24 created dlang/dmd pull request #11480 "Fix 19210: Poor error message for `return` function parameter that is not `ref`" fixing this issue: - Fix 19210: Poor error message for `return` function parameter that is not `ref` If the type does not have references, adding `return` won't help. This we only suggest adding `return` when it actually has an effect. In addition, value types parameter are now qualified of "local variable", because that's what they are. Last, when the error is on `this`, the message advise to annotate the function. https://github.com/dlang/dmd/pull/11480
Comment #2 by dlang-bot — 2020-07-31T09:59:38Z
dlang/dmd pull request #11480 "Fix 19210: Poor error message for `return` function parameter that is not `ref`" was merged into master: - 0f4d552a012575d2f9488255606c29ce9a238649 by Geod24: Fix 19210: Poor error message for `return` function parameter that is not `ref` If the type does not have references, adding `return` won't help. This we only suggest adding `return` when it actually has an effect. In addition, value types parameter are now qualified of "local variable", because that's what they are. Last, when the error is on `this`, the message advise to annotate the function. https://github.com/dlang/dmd/pull/11480
Comment #3 by pro.mathias.lang — 2020-09-03T02:32:34Z
*** Issue 19742 has been marked as a duplicate of this issue. ***