diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-08-29 00:35:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-29 00:35:05 +0200 |
commit | 5f7a6aff06e80fb27f5edb855a4592a8d935906b (patch) | |
tree | 423e42eee59ace918c551ff2f90cd72605dd38f1 | |
parent | 21fc8b4d4d82637fab831cffed0e5b995ec7f16c (diff) | |
download | Nim-5f7a6aff06e80fb27f5edb855a4592a8d935906b.tar.gz |
fixes #11941 (#12079)
-rw-r--r-- | compiler/sem.nim | 9 | ||||
-rw-r--r-- | compiler/semtypes.nim | 2 | ||||
-rw-r--r-- | tests/template/template_issues.nim | 15 |
3 files changed, 23 insertions, 3 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim index 70a84501f..ecf5e4f85 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -403,7 +403,13 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode, if s.typ.sons[0] == nil: result = semStmt(c, result, flags) else: - case s.typ.sons[0].kind + var retType = s.typ.sons[0] + if retType.kind == tyTypeDesc and tfUnresolved in retType.flags and + retType.len == 1: + # bug #11941: template fails(T: type X, v: auto): T + # does not mean we expect a tyTypeDesc. + retType = retType[0] + case retType.kind of tyUntyped: # Not expecting a type here allows templates like in ``tmodulealias.in``. result = semExpr(c, result, flags) @@ -421,7 +427,6 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode, result.typ = makeTypeDesc(c, typ) #result = symNodeFromType(c, typ, n.info) else: - var retType = s.typ.sons[0] if s.ast[genericParamsPos] != nil and retType.isMetaType: # The return type may depend on the Macro arguments # e.g. template foo(T: typedesc): seq[T] diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 6e542237b..9fec57b15 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1799,7 +1799,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = of nkStmtListType: result = semStmtListType(c, n, prev) of nkBlockType: result = semBlockType(c, n, prev) else: - localError(c.config, n.info, errTypeExpected) + localError(c.config, n.info, "type expected, but got: " & renderTree(n)) result = newOrPrevType(tyError, prev, c) n.typ = result dec c.inTypeContext diff --git a/tests/template/template_issues.nim b/tests/template/template_issues.nim index dd545d1e2..b7dd2a1a7 100644 --- a/tests/template/template_issues.nim +++ b/tests/template/template_issues.nim @@ -6,6 +6,7 @@ output: ''' a hi Hello, World! +(e: 42) ''' """ @@ -220,3 +221,17 @@ block t5235: outer: test("Hello, World!") + + +# bug #11941 +type X = object + e: int + +proc works(T: type X, v: auto): T = T(e: v) +template fails(T: type X, v: auto): T = T(e: v) + +var + w = X.works(42) + x = X.fails(42) + +echo x |