Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ambiguous identifier message to generic instantiations #24646

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)