From d5c9255cab9c111f8fa930e4cd42d6671877bd9d Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 24 Jul 2018 08:25:08 +0200 Subject: [PATCH] Allow use of typedesc as type converters (#8409) Fixes #8403 --- compiler/semtypes.nim | 10 ++++++++-- tests/generics/t8403.nim | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/generics/t8403.nim diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 05a9d9882a..1205cc406c 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1577,8 +1577,14 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = result = prev of nkSym: let s = getGenSym(c, n.sym) - if s.kind == skType and s.typ != nil: - var t = s.typ + if s.kind == skType and s.typ != nil or + s.kind == skParam and s.typ.kind == tyTypeDesc: + var t = + if s.kind == skType: + s.typ + else: + internalAssert c.config, s.typ.base.kind != tyNone and prev == nil + s.typ.base let alias = maybeAliasType(c, t, prev) if alias != nil: result = alias diff --git a/tests/generics/t8403.nim b/tests/generics/t8403.nim new file mode 100644 index 0000000000..47ce9c4523 --- /dev/null +++ b/tests/generics/t8403.nim @@ -0,0 +1,11 @@ +discard """ + output: "6.0" +""" + +proc sum*[T](s: seq[T], R: typedesc): R = + var sum: R = 0 + for x in s: + sum += R(x) + return sum + +echo @[1, 2, 3].sum(float)