Bug 14108 – template object.get cannot deduce function from argument types
Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2015-02-02T01:29:00Z
Last change time
2015-02-06T06:26:14Z
Assigned to
nobody
Creator
timothee.cour2
Comments
Comment #0 by timothee.cour2 — 2015-02-02T01:29:47Z
Not sure if it's related to 1370 but it still appears in git head (v2.067-devel-e542e14)
----
enum b=[
"a":1,
];
void main(){
char[]a="a".dup;
b.get(a,1);
b.get(a.idup,1);//error in git head
}
----
dmd -run main.d
Error: template object.get cannot deduce function from argument types !()(int[string], char[], int), candidates are:...
it worked in dmd 2.066 (v2.066-devel-4d3a95a)
Comment #1 by k.hara.pg — 2015-02-02T01:59:45Z
(In reply to Timothee Cour from comment #0)
> Not sure if it's related to 1370 but it still appears in git head
> (v2.067-devel-e542e14)
OT: I'm not sure what the "1370" is.
>
> ----
> enum b=[
> "a":1,
> ];
> void main(){
> char[]a="a".dup;
b.get(a,1); // error in git head
b.get(a.idup,1); // no error in git-head
The error is in `b.get(a,1);`.
> }
> ----
> dmd -run main.d
> Error: template object.get cannot deduce function from argument types
> !()(int[string], char[], int), candidates are:...
>
> it worked in dmd 2.066 (v2.066-devel-4d3a95a)
The type of b is int[string]. To access the AA, you have to use a key typed as `string`. Therefore using `a` typed char[] to access AA should be type mismatch error.
Honestly, dmd 2.066 has an IFTI regression that was not properly fixed. The line b.get(a,1); has been correctly rejected until 2.065. So, it was an "accepts-invalid bug only in 2.066 release.
Comment #2 by timothee.cour2 — 2015-02-02T04:06:52Z
>> OT: I'm not sure what the "1370" is.
bugzilla 1370
>>The type of b is int[string]. To access the AA, you have to use a key typed as `string`. Therefore using `a` typed char[] to access AA should be type mismatch error.
Honestly, dmd 2.066 has an IFTI regression that was not properly fixed. The line b.get(a,1); has been correctly rejected until 2.065. So, it was an "accepts-invalid bug only in 2.066 release.
But why can't a char[] be used here though? Seems to me it would be safe to allow that?
Comment #3 by bugzilla — 2015-02-06T04:54:18Z
(In reply to Timothee Cour from comment #2)
> But why can't a char[] be used here though? Seems to me it would be safe to
> allow that?
Because the associative array does not store a copy of the key, it stores the key. If the key is mutable, then it could change, and the associative array's data structure then becomes corrupt.
Comment #4 by timothee.cour2 — 2015-02-06T06:26:14Z
But the argument $key to aa.get(key) doesn't need to be stored, it's just used to retrieve the value with that key if it's there (eg by computing a hash function on the key, which doesn't need key to be immutable). Am I misunderstanding something?