diff options
author | metagn <metagngn@gmail.com> | 2023-09-01 16:37:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-01 15:37:16 +0200 |
commit | 6738f44af3866e4cace94d34b653acf3283f0cde (patch) | |
tree | 387274d16bc6cda0b1c1ce302ab3c6547bc00788 | |
parent | 0c6e13806d0abfad30b8a4bd9f1fe7858ff2125a (diff) | |
download | Nim-6738f44af3866e4cace94d34b653acf3283f0cde.tar.gz |
unify explicit generic param semchecking in calls (#22618)
fixes #9040
-rw-r--r-- | compiler/semcall.nim | 8 | ||||
-rw-r--r-- | compiler/semexprs.nim | 4 | ||||
-rw-r--r-- | tests/generics/timplicit_and_explicit.nim | 21 |
3 files changed, 26 insertions, 7 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim index adfc98e19..a4114497f 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -733,14 +733,18 @@ proc explicitGenericSym(c: PContext, n: PNode, s: PSym): PNode = onUse(info, s) result = newSymNode(newInst, info) -proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode = - assert n.kind == nkBracketExpr +proc setGenericParams(c: PContext, n: PNode) = + ## sems generic params in subscript expression for i in 1..<n.len: let e = semExprWithType(c, n[i]) if e.typ == nil: n[i].typ = errorType(c) else: n[i].typ = e.typ.skipTypes({tyTypeDesc}) + +proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode = + assert n.kind == nkBracketExpr + setGenericParams(c, n) var s = s var a = n[0] if a.kind == nkSym: diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index f612cd996..e9f90dcc0 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1003,10 +1003,6 @@ proc bracketedMacro(n: PNode): PSym = else: result = nil -proc setGenericParams(c: PContext, n: PNode) = - for i in 1..<n.len: - n[i].typ = semTypeNode(c, n[i], nil) - proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags; expectedType: PType = nil): PNode = if efNoSemCheck notin flags and n.typ != nil and n.typ.kind == tyError: return errorNode(c, n) diff --git a/tests/generics/timplicit_and_explicit.nim b/tests/generics/timplicit_and_explicit.nim index ba24b79e9..fe61004e4 100644 --- a/tests/generics/timplicit_and_explicit.nim +++ b/tests/generics/timplicit_and_explicit.nim @@ -42,4 +42,23 @@ block: #4688 block: #4164 proc printStr[T](s: static[string]): T = discard - discard printStr[int]("hello static") \ No newline at end of file + discard printStr[int]("hello static") + +import macros + +block: # issue #9040, statics with template, macro, symchoice explicit generics + block: # macro + macro fun[N: static int](): untyped = + newLit 1 + const a = fun[2]() + doAssert a == 1 + block: # template + template fun[N: static int](): untyped = + 1 + const a = fun[2]() + doAssert a == 1 + block: # symchoice + proc newSeq[x: static int](): int = 1 + template foo: int = + newSeq[2]() + doAssert foo() == 1 |