mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-17 21:12:42 +00:00
add ambiguous identifier message to generic instantiations (#24646)
fixes #24644
Another option is to include the symbol names and owners in the type
listing as in #24645 but this is a bit verbose.
(cherry picked from commit 0861dabfa7)
This commit is contained in:
@@ -1671,6 +1671,11 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
|
||||
var err = "cannot instantiate "
|
||||
err.addTypeHeader(c.config, t)
|
||||
err.add "\ngot: <$1>\nbut expected: <$2>" % [describeArgs(c, n), describeArgs(c, t.n, 0)]
|
||||
if m.firstMismatch.kind == kTypeMismatch and m.firstMismatch.arg < n.len:
|
||||
let nArg = n[m.firstMismatch.arg]
|
||||
if nArg.kind in nkSymChoices:
|
||||
err.add "\n"
|
||||
err.add ambiguousIdentifierMsg(nArg)
|
||||
localError(c.config, n.info, errGenerated, err)
|
||||
return newOrPrevType(tyError, prev, c)
|
||||
|
||||
|
||||
11
tests/errmsgs/tambtypegeneric.nim
Normal file
11
tests/errmsgs/tambtypegeneric.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
import "."/[mambtype1, mambtype2]
|
||||
type H[K] = object
|
||||
proc b(_: int) = # slightly different, still not useful, error message if `b` generic
|
||||
proc r(): H[Y] = discard #[tt.Error
|
||||
^ cannot instantiate H [type declared in tambtypegeneric.nim(2, 6)]
|
||||
got: <typedesc[Y] | typedesc[Y]>
|
||||
but expected: <K>
|
||||
ambiguous identifier: 'Y' -- use one of the following:
|
||||
mambtype1.Y: Y
|
||||
mambtype2.Y: Y]#
|
||||
b(0)
|
||||
Reference in New Issue
Block a user