diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index b3b8c27fc405..a2d1c4b77519 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1694,11 +1694,9 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode = else: # We are processing macroOrTmpl[] not in call. Transform it to the # macro or template call with generic arguments here. - n.transitionSonsKind(nkCall) - case s.kind - of skMacro: result = semMacroExpr(c, n, n, s, flags) - of skTemplate: result = semTemplateExpr(c, n, s, flags) - else: discard + setGenericParams(c, n, nil) + let call = newTreeI(nkCall, n.info, n) + result = semDirectOp(c, call, flags) of skType: result = symNodeFromType(c, semTypeNode(c, n, nil), n.info) else: diff --git a/tests/macros/tsubscript.nim b/tests/macros/tsubscript.nim new file mode 100644 index 000000000000..4934fee11c65 --- /dev/null +++ b/tests/macros/tsubscript.nim @@ -0,0 +1,7 @@ +macro foo[T](x: T) = discard +doAssert not compiles(foo[abc]) + +template bar[T](): untyped = T(0) +let x = bar[int] +doAssert x == 0 +doAssert not compiles(bar[abc])