Bug 7600 – Generate better error message with lvalue mismatch

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-27T06:28:13Z
Last change time
2019-11-30T09:39:58Z
Assigned to
No Owner
Creator
Andrej Mitrovic

Comments

Comment #0 by andrej.mitrovich — 2012-02-27T06:28:13Z
void foo(ref string x) { } void bar(ref int x) { } void main() { foo("var"); immutable int x; bar(x); } test.d(8): Error: function test.foo (ref string x) is not callable using argument types (string) test.d(10): Error: function test.bar (ref int x) is not callable using argument types (immutable(int)) test.d(10): Error: constant 0 is not an lvalue The error for the 'foo' function should generate two error messages just like the error for 'bar. It could print: 'Error: constant "var" is not an lvalue'. This is especially useful in templated functions.
Comment #1 by bearophile_hugs — 2012-02-27T10:20:54Z
(In reply to comment #0) > test.d(8): Error: function test.foo (ref string x) is not callable using > argument types (string) > > test.d(10): Error: function test.bar (ref int x) is not callable using argument > types (immutable(int)) > test.d(10): Error: constant 0 is not an lvalue > > The error for the 'foo' function should generate two error messages just like > the error for 'bar. > > It could print: 'Error: constant "var" is not an lvalue'. This is especially > useful in templated functions. Or maybe better, generate a single error message in both cases, something like: test.d(10): Error: function test.bar (ref int x) is not callable using argument types (immutable(int)), constant 0 is not an lvalue.
Comment #2 by razvan.nitu1305 — 2019-11-30T09:39:58Z
It now prints: onlineapp.d(6): Error: function onlineapp.foo(ref string x) is not callable using argument types (string) onlineapp.d(6): cannot pass rvalue argument "var" of type string to parameter ref string x onlineapp.d(8): Error: function onlineapp.bar(ref int x) is not callable using argument types (immutable(int)) onlineapp.d(8): cannot pass argument x of type immutable(int) to parameter ref int x Which is the correct behavior. Closing as fixed.