.get refuses to work on associative array
p.shkadzko
p.shkadzko at gmail.com
Wed Apr 15 21:46:58 UTC 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?
More information about the Digitalmars-d-learn
mailing list