From bd709f9b4c4911755c7cfb7567ddae71b2f9ac46 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sun, 1 Mar 2026 06:01:09 +0800 Subject: [PATCH] fixes #25262; proc v[T: typedesc]() = discard / v[0]() compiles even though 0 isn't a typedesc (#25558) fixes #25262 ```nim if constraint != nil and constraint.kind == tyTypeDesc: n[i].typ = e.typ else: n[i].typ = e.typ.skipTypes({tyTypeDesc}) ``` at least when `constraint` is a typedesc, it should not skip `tyTypeDesc` ```nim if arg.kind != tyTypeDesc: arg = makeTypeDesc(m.c, arg) ``` Wrappers literals into typedesc, which can cause problems. Though, it doesn't seem to be necessary --- compiler/semcall.nim | 2 +- compiler/sigmatch.nim | 3 +-- tests/generics/tpointerprocs.nim | 2 +- tests/typerel/t25262.nim | 13 +++++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/typerel/t25262.nim diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 4557ab4c69..29d19875d4 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -981,7 +981,7 @@ proc setGenericParams(c: PContext, n, expectedParams: PNode) = if e.typ == nil: n[i].typ = errorType(c) else: - n[i].typ = e.typ.skipTypes({tyTypeDesc}) + n[i].typ = e.typ proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym, doError: bool): PNode = assert n.kind == nkBracketExpr diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 7839a1a5cb..2e46d508ae 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -160,8 +160,7 @@ proc matchGenericParam(m: var TCandidate, formal: PType, n: PNode) = arg = newTypeS(tyStatic, m.c, son = evaluated.typ) arg.n = evaluated elif formalBase.kind == tyTypeDesc: - if arg.kind != tyTypeDesc: - arg = makeTypeDesc(m.c, arg) + discard # if arg is not tyTypeDesc, typeRel will report the mismatch else: arg = arg.skipTypes({tyTypeDesc}) let tm = typeRel(m, formal, arg) diff --git a/tests/generics/tpointerprocs.nim b/tests/generics/tpointerprocs.nim index 29c4f2954f..ba99044645 100644 --- a/tests/generics/tpointerprocs.nim +++ b/tests/generics/tpointerprocs.nim @@ -3,7 +3,7 @@ cmd: "nim check $options --hints:off $file" action: "reject" nimout:''' tpointerprocs.nim(22, 11) Error: 'foo' doesn't have a concrete type, due to unspecified generic parameters. -tpointerprocs.nim(34, 14) Error: type mismatch: got +tpointerprocs.nim(34, 14) Error: type mismatch: got but expected one of: proc foo(x: int | float; y: int or string): float first type mismatch at position: 2 in generic parameters diff --git a/tests/typerel/t25262.nim b/tests/typerel/t25262.nim new file mode 100644 index 0000000000..182561dde3 --- /dev/null +++ b/tests/typerel/t25262.nim @@ -0,0 +1,13 @@ +discard """ + errormsg: "type mismatch" + output: ''' +t25262.nim(13, 5) Error: type mismatch: got <> +but expected one of: +proc v[T: typedesc]() + +expression: v[0]() +''' +""" + +proc v[T: typedesc]() = discard +v[0]() \ No newline at end of file