mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Return an error symbol as macro output if needed (#8116)
Return an error symbol if the macro output has no type and a typedesc is expected. Fixes #7454
This commit is contained in:
@@ -412,7 +412,12 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode,
|
||||
of tyTypeDesc:
|
||||
if result.kind == nkStmtList: result.kind = nkStmtListType
|
||||
var typ = semTypeNode(c, result, nil)
|
||||
result.typ = makeTypeDesc(c, typ)
|
||||
if typ == nil:
|
||||
localError(c.config, result.info, "expression has no type: " &
|
||||
renderTree(result, {renderNoComments}))
|
||||
result = newSymNode(errorSym(c, result))
|
||||
else:
|
||||
result.typ = makeTypeDesc(c, typ)
|
||||
#result = symNodeFromType(c, typ, n.info)
|
||||
else:
|
||||
var retType = s.typ.sons[0]
|
||||
|
||||
8
tests/macros/t7454.nim
Normal file
8
tests/macros/t7454.nim
Normal file
@@ -0,0 +1,8 @@
|
||||
discard """
|
||||
errormsg: "expression has no type:"
|
||||
line: 8
|
||||
"""
|
||||
|
||||
macro p(t: typedesc): typedesc =
|
||||
discard
|
||||
var a: p(int)
|
||||
Reference in New Issue
Block a user