Thread overview
.get refuses to work on associative array
Apr 15, 2020
p.shkadzko
Apr 15, 2020
H. S. Teoh
Apr 15, 2020
bauss
Apr 16, 2020
p.shkadzko
April 15, 2020
I am quite confused by the following exception during dub build:

> dub build --single demo.d --compiler=ldc2 --force
Performing "debug" build using ldc2 for x86_64.
demo ~master: building configuration "application"...
demo.d(221,20): Error: template object.get cannot deduce function from argument types !()(double[string], string, string), candidates are:
C:\ldc2-1.20.0-windows-x64\bin\..\import\object.d(2645,10):        get(K, V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)
C:\ldc2-1.20.0-windows-x64\bin\..\import\object.d(2652,10):        get(K, V)(inout(V[K])* aa, K key, lazy inout(V) defaultValue)

The code that causes it:

"""
void main(string[] args) {

    double[string] scores = calculateScores("test.txt");
    double score = scores.get("hello", 0.0); // <-- exception
}
"""

It works if I just do "double score = scores["hello"];"
Both dmd and ldc2 throw this exception.
Is it a bug?
April 15, 2020
On Wed, Apr 15, 2020 at 09:46:58PM +0000, p.shkadzko via Digitalmars-d-learn wrote:
> I am quite confused by the following exception during dub build:
> 
> > dub build --single demo.d --compiler=ldc2 --force
> Performing "debug" build using ldc2 for x86_64.
> demo ~master: building configuration "application"...
> demo.d(221,20): Error: template object.get cannot deduce function from
> argument types !()(double[string], string, string), candidates are:
> C:\ldc2-1.20.0-windows-x64\bin\..\import\object.d(2645,10):        get(K,
> V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)
> C:\ldc2-1.20.0-windows-x64\bin\..\import\object.d(2652,10):        get(K,
> V)(inout(V[K])* aa, K key, lazy inout(V) defaultValue)
> 
> The code that causes it:
> 
> """
> void main(string[] args) {
> 
>     double[string] scores = calculateScores("test.txt");
>     double score = scores.get("hello", 0.0); // <-- exception
> }
> """
> 
> It works if I just do "double score = scores["hello"];"
> Both dmd and ldc2 throw this exception.
> Is it a bug?

Are you sure the error is on the line you indicated? The error message
claims that your argument types are (double[string], string, string),
but your code clearly has argument types (double[sting], string,
double).  Are you sure dub is compiling the source file(s) you think
it's compiling?  Which source file(s) are shown by `dub -v`?


T

-- 
Leather is waterproof.  Ever see a cow with an umbrella?
April 15, 2020
On Wednesday, 15 April 2020 at 22:09:32 UTC, H. S. Teoh wrote:
> On Wed, Apr 15, 2020 at 09:46:58PM +0000, p.shkadzko via Digitalmars-d-learn wrote:
>> I am quite confused by the following exception during dub build:
>> 
>> > dub build --single demo.d --compiler=ldc2 --force
>> Performing "debug" build using ldc2 for x86_64.
>> demo ~master: building configuration "application"...
>> demo.d(221,20): Error: template object.get cannot deduce function from
>> argument types !()(double[string], string, string), candidates are:
>> C:\ldc2-1.20.0-windows-x64\bin\..\import\object.d(2645,10):
>>     get(K,
>> V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue)
>> C:\ldc2-1.20.0-windows-x64\bin\..\import\object.d(2652,10):
>>     get(K,
>> V)(inout(V[K])* aa, K key, lazy inout(V) defaultValue)
>> 
>> The code that causes it:
>> 
>> """
>> void main(string[] args) {
>> 
>>     double[string] scores = calculateScores("test.txt");
>>     double score = scores.get("hello", 0.0); // <-- exception
>> }
>> """
>> 
>> It works if I just do "double score = scores["hello"];"
>> Both dmd and ldc2 throw this exception.
>> Is it a bug?
>
> Are you sure the error is on the line you indicated? The error message
> claims that your argument types are (double[string], string, string),
> but your code clearly has argument types (double[sting], string,
> double).  Are you sure dub is compiling the source file(s) you think
> it's compiling?  Which source file(s) are shown by `dub -v`?
>
>
> T

It also says line 221. In which case he should be able to track it down to line 221 and see where the error is.
April 16, 2020
On Wednesday, 15 April 2020 at 22:09:32 UTC, H. S. Teoh wrote:
> On Wed, Apr 15, 2020 at 09:46:58PM +0000, p.shkadzko via Digitalmars-d-learn wrote:
>> [...]
>
> Are you sure the error is on the line you indicated? The error message
> claims that your argument types are (double[string], string, string),
> but your code clearly has argument types (double[sting], string,
> double).  Are you sure dub is compiling the source file(s) you think
> it's compiling?  Which source file(s) are shown by `dub -v`?
>
>
> T

I should stop programming at night. Indeed it was the incorrect .get("a", "NULL") instead of .get("a", 0.0), sigh. Sorry guys.