Skip to content

Commit

Permalink
add ambiguous identifier message to generic instantiations
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Jan 24, 2025
1 parent 1f9cac1 commit 0f61a0e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions tests/errmsgs/tambtypegeneric.nim
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0f61a0e

Please sign in to comment.