Skip to content

Commit

Permalink
fix nim-lang#10833 type expected error for proc resolution with stati…
Browse files Browse the repository at this point in the history
…c[int]]
  • Loading branch information
bung87 committed Sep 26, 2022
1 parent be4bd8a commit 0cb7318
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 0 additions & 6 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1232,12 +1232,6 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode =
# deal with two different ``[]``.
if s.ast.safeLen == 0: result = inlineConst(c, n, s)
else: result = newSymNode(s, n.info)
of tyStatic:
if typ.n != nil:
result = typ.n
result.typ = typ.base
else:
result = newSymNode(s, n.info)
else:
result = newSymNode(s, n.info)
of skMacro:
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 0cb7318

Please sign in to comment.