Bug 8213 – Incorrect error message with pointer to ubyte[] and front
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-09T02:21:00Z
Last change time
2015-06-09T05:14:51Z
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2012-06-09T02:21:47Z
This code
import std.array;
struct S(R)
{
this(R* range)
{
_range = range;
}
auto front()
{
return _range.front;
}
R* _range;
}
void main()
{
ubyte[] buffer = [42];
auto s = S!(ubyte[])(&buffer);
auto f = s.front;
}
results in this error:
q.d(12): Error: no property 'front' for type 'ubyte[]'
q.d(21): Error: template instance q.S!(ubyte[]) error instantiating
I'm tempted to argue that this should just compile, since . automatically dereferences the type that it's on if it's a pointer, and the type in question (ubyte[]) has a front via std.array, but _range itself doesn't match front's parameters, because it's a pointer to a ubyte[] rather than a ubyte[], so I suspect that this _isn't_ supposed to work much as I'd like it to. If it _is_ supposed to work, however, then this obviously shows that it isn't currently and is therefore a bug.
Regardless of the correct behavior, however, the error message is bad. It says that ubyte[] has no property front, which is not only not true, but the type which is failing is ubyte[]*, not ubyte[], so the type in the error message is wrong.
Either this code needs to be fixed so that it compiles and works just fine (automatically dereferencing the pointer and using the type of the dereferenced pointer rather than the pointer itself when lookin for functions to use with UFCS), or the error needs to be fixed so that it gives the correct type.
Comment #1 by verylonglogin.reg — 2013-04-19T01:25:44Z
See also Issue 8245 (probably, one can say it's a dup).
Comment #2 by verylonglogin.reg — 2013-04-23T03:22:59Z
The error gives the correct type now:
---
main.d(12): Error: template std.array.front does not match any function template declaration. Candidates are:
<phobos path>\std\array.d(584): std.array.front(T)(T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[]))
<phobos path>\std\array.d(605): std.array.front(T)(T[] a) if (isNarrowString!(T[]))
<phobos path>\std\array.d(584): Error: template std.array.front cannot deduce template function from argument types !()(ubyte[]*)
main.d(21): Error: template instance main.S!(ubyte[]) error instantiating
main.d(22): Error: not a property s.front
---
Comment #3 by k.hara.pg — 2013-04-24T00:34:19Z
(In reply to comment #2)
> The error gives the correct type now:
> ---
> main.d(12): Error: template std.array.front does not match any function
> template declaration. Candidates are:
> <phobos path>\std\array.d(584): std.array.front(T)(T[] a) if
> (!isNarrowString!(T[]) && !is(T[] == void[]))
> <phobos path>\std\array.d(605): std.array.front(T)(T[] a) if
> (isNarrowString!(T[]))
> <phobos path>\std\array.d(584): Error: template std.array.front cannot deduce
> template function from argument types !()(ubyte[]*)
> main.d(21): Error: template instance main.S!(ubyte[]) error instantiating
> main.d(22): Error: not a property s.front
> ---
In 2.063a, error message with UFCS issues are got fixed. So I'll close this.
Currently automatic pointer dereference is not supported in UFCS name look up. For the issue, I'll mark issue 8597 as enhancement.