D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7600 - Generate better error message with lvalue mismatch
Summary: Generate better error message with lvalue mismatch
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-27 06:28 UTC by Andrej Mitrovic
Modified: 2019-11-30 09:39 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2012-02-27 06:28:13 UTC
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 bearophile_hugs 2012-02-27 10:20:54 UTC
(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 RazvanN 2019-11-30 09:39:58 UTC
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.