D-Programming-Language/dmd — pull request #1407 by AndrejMitrovic (2012-12-25 14:31:34+00:00)
Title: Issue 1730 - Error message on 'this' reference modifier mismatch is uninformative

http://d.puremagic.com/issues/show_bug.cgi?id=1730 (and many duplicates which have to be marked as such)

Small gift for Xmas!

Note 1: I can't simply write `non-modifier`, because the modifier can be e.g. `shared const`, and the error message would then be misleading: `non-shared const`. So I'm simply adding a space after the `non` part.

Note 2: If there is a modifier mismatch the error `is not callable using argument types` is not shown. The reason why is to avoid double error messages where the only problem was the modifier, for example:

```D
struct S
{
void func() { }
}

void main()
{
const(S) cObj;
cObj.func();
}
```

When both errors are printed:

```
Fix1730.d(30): Error: const object cannot call non const method Fix1730.S.func
Fix1730.d(30): Error: function Fix1730.S.func () is not callable using argument types () const
```

But only the first error message is necessary, so in this pull it's:

```
Fix1730.d(30): Error: const object cannot call non const method Fix1730.S.func
```

However maybe I should let the second error message go through because we can have both a modifier and parameter mismatch:

```D
struct S
{
void func(int) { }
}

void main()
{
const(S) cObj;
cObj.func("");
}
```

When both errors are shown:

```
test.d(9): Error: const object cannot call non const method test.S.func
test.d(9): Error: function test.S.func (int _param_0) is not callable using argument types (string) const
test.d(9): Error: cannot implicitly convert expression ("") of type string to int
```

Currently in pull it's:

```
test.d(9): Error: const object cannot call non const method test.S.func
test.d(9): Error: cannot implicitly convert expression ("") of type string to int
```

Note that eventually the error will be printed as soon as the user fixes the mod-mismatch, so it's not lost, it's just hidden if there are any modifier errors.

So should I let the `is not callable using` message print every time or leave it as is in the pull?