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

whitelist generic params matching typedesc for templates/macros #23438

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1905,10 +1905,12 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
# when `f` is an unresolved typedesc, `a` could be any
# type, so we should not perform this check earlier
if c.c.inGenericContext > 0 and
a.skipTypes({tyTypeDesc}).kind == tyGenericParam:
a.skipTypes({tyTypeDesc}).kind == tyGenericParam and
not (c.calleeSym != nil and c.calleeSym.kind in {skMacro, skTemplate}):
# generic type bodies can sometimes compile call expressions
# prevent unresolved generic parameters from being passed to procs as
# typedesc parameters
# macros and templates receive a pass for practicality
result = isNone
elif a.kind != tyTypeDesc:
if a.kind == tyGenericParam and tfWildcard in a.flags:
Expand Down
28 changes: 28 additions & 0 deletions tests/generics/tmacrotype.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import std/[sequtils, macros]

block: # issue #23432
type
Future[T] = object
InternalRaisesFuture[T, E] = object

macro Raising[T](F: typedesc[Future[T]], E: varargs[typedesc]): untyped =
## Given a Future type instance, return a type storing `{.raises.}`
## information
##
## Note; this type may change in the future
E.expectKind(nnkBracket)

let raises = nnkTupleConstr.newTree(E.mapIt(it))
nnkBracketExpr.newTree(
ident "InternalRaisesFuture",
nnkDotExpr.newTree(F, ident"T"),
raises
)

type X[E] = Future[void].Raising(E)

proc f(x: X) = discard


var v: Future[void].Raising([ValueError])
f(v)
Loading