Try conversion to static[T] in generic instantation (#8443)
Fixes #8439
This commit is contained in:
parent
becb6743f8
commit
c3a9ac4d35
2 changed files with 19 additions and 1 deletions
|
|
@ -505,7 +505,15 @@ proc explicitGenericSym(c: PContext, n: PNode, s: PSym): PNode =
|
||||||
|
|
||||||
for i in 1..sonsLen(n)-1:
|
for i in 1..sonsLen(n)-1:
|
||||||
let formal = s.ast.sons[genericParamsPos].sons[i-1].typ
|
let formal = s.ast.sons[genericParamsPos].sons[i-1].typ
|
||||||
let arg = n[i].typ
|
var arg = n[i].typ
|
||||||
|
# try transforming the argument into a static one before feeding it into
|
||||||
|
# typeRel
|
||||||
|
if formal.kind == tyStatic and arg.kind != tyStatic:
|
||||||
|
let evaluated = c.semTryConstExpr(c, n[i])
|
||||||
|
if evaluated != nil:
|
||||||
|
arg = newTypeS(tyStatic, c)
|
||||||
|
arg.sons = @[evaluated.typ]
|
||||||
|
arg.n = evaluated
|
||||||
let tm = typeRel(m, formal, arg)
|
let tm = typeRel(m, formal, arg)
|
||||||
if tm in {isNone, isConvertible}: return nil
|
if tm in {isNone, isConvertible}: return nil
|
||||||
var newInst = generateInstance(c, s, m.bindings, n.info)
|
var newInst = generateInstance(c, s, m.bindings, n.info)
|
||||||
|
|
|
||||||
10
tests/generics/t8439.nim
Normal file
10
tests/generics/t8439.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
discard """
|
||||||
|
output: "1"
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
Cardinal = enum
|
||||||
|
north, east, south, west
|
||||||
|
|
||||||
|
proc foo[cardinal: static[Cardinal]](): int = 1
|
||||||
|
echo(foo[north]())
|
||||||
Loading…
Add table
Add a link
Reference in a new issue