Skip to content

Commit

Permalink
fix #10833 type expected error for proc resolution with static[int]]
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Sep 25, 2022
1 parent be4bd8a commit 517d282
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,10 @@ proc semProcBody(c: PContext, n: PNode; expectedType: PType = nil): PNode =
else:
var a = newNodeI(nkAsgn, n.info, 2)
a[0] = newSymNode(c.p.resultSym)
for s in c.p.resultSym.typ.sons.mitems:
if s != nil:
if s.kind == tyStatic:
s = s.base
a[1] = result
result = semAsgn(c, a)
else:
Expand Down
7 changes: 5 additions & 2 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ proc semTypeIdent(c: PContext, n: PNode): PSym =
if n.kind == nkSym:
result = getGenSym(c, n.sym)
else:
result = pickSym(c, n, {skType, skGenericParam, skParam})
result = pickSym(c, n, {skType, skGenericParam, skParam, skConst})
if result.isNil:
result = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared})
if result != nil:
Expand Down Expand Up @@ -437,7 +437,7 @@ proc semTypeIdent(c: PContext, n: PNode): PSym =
else:
localError(c.config, n.info, errTypeExpected)
return errorSym(c, n)
if result.kind != skType and result.magic notin {mStatic, mType, mTypeOf}:
if result.kind notin {skType, skConst} and result.magic notin {mStatic, mType, mTypeOf}:
# this implements the wanted ``var v: V, x: V`` feature ...
var ov: TOverloadIter
var amb = initOverloadIter(ov, c, n)
Expand All @@ -448,6 +448,9 @@ proc semTypeIdent(c: PContext, n: PNode): PSym =
if result.kind != skError: localError(c.config, n.info, errTypeExpected)
return errorSym(c, n)
if result.typ.kind != tyGenericParam:
if result.kind == skConst:
return result

# XXX get rid of this hack!
var oldInfo = n.info
when defined(useNodeIds):
Expand Down
14 changes: 14 additions & 0 deletions tests/generics/t10833.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type Foo*[A; B; C: static[int]] = object
s: string

proc build*[A; B; C: static[int]](s: string;): Foo[A, B, C] =
result.s = s

proc build*[A; B; C: static[int]](): Foo[A, B, C] =
build[A, B, C]("foo")

type
Bar = object
Baz = object
let r = build[Bar, Baz, 1]()
doAssert r.s == "foo"

0 comments on commit 517d282

Please sign in to comment.