Commit c0e65c4
authored
Match query type variables against concrete types (#488)
A type search for `a -> HTMLElement` previously returned no concrete
results where `_ -> HTMLElement` matched functions like
`HTMLAnchorElement -> HTMLElement`, because compareTypes had no case for
a query-side type variable against a concrete type (#395).
Query variables now match any concrete type, as wildcards do, except
that each instantiation charges a penalty of 1 - less than a single
unit of structural mismatch (10) - so results that unify with the query
directly still rank first. Each instantiation is also recorded against
the variable's name and fed through typeVarPenalty, so repeated query
variables must be instantiated consistently: for the query `a -> a`,
`Int -> Int` ranks above `Int -> String`.
Existing comparisons are unaffected: no previously-matching clause
changed, so current rankings only gain new, lower-ranked results.
Also fixes the compareTypes doc examples, which had a typo (parseType
s2 twice) and a stale expected score predating the 10x score scaling.
Based on #396 by @klntsky.1 parent d1c6bfd commit c0e65c4
3 files changed
Lines changed: 57 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
8 | 15 | | |
9 | 16 | | |
10 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
| 406 | + | |
407 | 407 | | |
408 | 408 | | |
409 | | - | |
410 | | - | |
411 | 409 | | |
| 410 | + | |
| 411 | + | |
412 | 412 | | |
413 | | - | |
414 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
415 | 416 | | |
416 | 417 | | |
417 | 418 | | |
418 | 419 | | |
419 | 420 | | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
425 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
426 | 437 | | |
427 | 438 | | |
428 | 439 | | |
| |||
448 | 459 | | |
449 | 460 | | |
450 | 461 | | |
451 | | - | |
| 462 | + | |
452 | 463 | | |
453 | 464 | | |
454 | 465 | | |
| |||
459 | 470 | | |
460 | 471 | | |
461 | 472 | | |
462 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
463 | 477 | | |
464 | 478 | | |
465 | 479 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
0 commit comments