Bug 12290 – IFTI should consider implicit conversions of the literal arguments

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-03T00:15:00Z
Last change time
2014-03-03T08:10:38Z
Keywords
pull
Assigned to
nobody
Creator
k.hara.pg
Blocks
12220

Comments

Comment #0 by k.hara.pg — 2014-03-03T00:15:25Z
Test case: inout(V) get(K, V)(inout(V[K]) aa, K key, lazy inout(V) defaultValue) { auto p = key in aa; return p ? *p : defaultValue; } void main() { short[short] aa = [1:10, 2:20]; short n = get(aa, 5, 50); // IFTI should deduce K=short, V=short from the arguments // !()(short[short], int, int) // because 1 and 2 are implicitly convertible to short // , and 10 and 20 are implicitly convertible to short assert(n == 50); }
Comment #1 by k.hara.pg — 2014-03-03T01:22:22Z
Comment #2 by github-bugzilla — 2014-03-03T07:06:18Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bdcee4d07905130240b0cacd604354994ddc915d fix Issue 12290 - IFTI should consider implicit conversions of the literal arguments https://github.com/D-Programming-Language/dmd/commit/826b764fd4a133ebf1179e76d8df9d8241032e3c Merge pull request #3353 from 9rnsr/fix12290 Issue 12290 - IFTI should consider implicit conversions of the literal arguments
Comment #3 by schveiguy — 2014-03-03T07:35:11Z
Somewhat related to issue 4998
Comment #4 by k.hara.pg — 2014-03-03T08:03:59Z
(In reply to comment #3) > Somewhat related to issue 4998 It's not related (and looks to me that would be impossible) issue.
Comment #5 by schveiguy — 2014-03-03T08:10:38Z
Definitely related. In both cases, the compiler is inferring the type of the literal based on the defined type of the literal rather than how it's used. In both cases, choosing a smaller integer type will satisfy the call, and should be done. Yes, in 4998, the example does not provide enough information in the signature itself to figure out the correct type to use, which is why the proposal is given.