digitalmars.D.bugs - [Issue 11120] New: Compiler calls wrong property when using type tuple of length 1
- d-bugmail puremagic.com (102/102) Sep 24 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11120
http://d.puremagic.com/issues/show_bug.cgi?id=11120
Summary: Compiler calls wrong property when using type tuple of
length 1
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: andrej.mitrovich gmail.com
16:04:30 PDT ---
-----
module test;
int glob;
struct K
{
property void max(int) { }
disable property ref int max() { return glob; }
alias setMax = _chainerFunc!max;
template _chainerFunc(alias symbol)
{
import std.traits;
alias Params = ParameterTypeTuple!symbol;
auto ref _chainerFunc(Params[0] args) // ok
{
symbol = args;
return this;
}
}
}
struct F
{
property void max(int) { }
disable property ref int max() { return glob; }
alias setMax = _chainerFunc!max;
template _chainerFunc(alias symbol)
{
import std.traits;
alias Params = ParameterTypeTuple!symbol;
auto ref _chainerFunc(Params args) // fail
{
symbol = args; // Error: attempts to call getter
return this;
}
}
}
void main()
{
K k;
k.max = 2;
k.setMax(1).setMax(2); // chaining example
F f;
f.max = 2;
f.setMax(1).setMax(2); // ditto
}
-----
$ dmd test.d
fail.d(39): Error: function test.F.max is not callable because it is annotated
with disable
fail.d(39): Error: cannot implicitly convert expression (tuple(_param_0)) of
type (int) to int
The code in "main()" is not needed but demonstrates the usage. Note how the
compiler wants to call the wrong property function (the getter instead of the
setter).
The above hurts generic code having to use Params[0] when the length is already
known to equal 1.
-- Please note: The bug goes away if there is no getter property, but only a
property setter is available. Observe:
-----
module test;
struct K
{
property void max(int) { }
// commented out
// property int max() { return 1; }
alias setMax = _chainerFunc!max;
template _chainerFunc(alias symbol)
{
import std.traits;
alias Params = ParameterTypeTuple!symbol;
// ok, now works without Params[0]
auto ref _chainerFunc(Params args)
{
symbol = args;
return this;
}
}
}
void main()
{
K k;
k.max = 2;
k.setMax(1).setMax(2); // chaining example
}
-----
So I think this is a bug, and not an enhancement.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 24 2013








d-bugmail puremagic.com