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 24, 2022
1 parent be4bd8a commit 9e36998
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ proc fitNode(c: PContext, formal: PType, arg: PNode; info: TLineInfo): PNode =
else:
result = indexTypesMatch(c, formal, arg.typ, arg)
if result == nil:
typeMismatch(c.config, info, formal, arg.typ, arg)
# typeMismatch(c.config, info, formal, arg.typ, arg)
# error correction:
result = copyTree(arg)
result.typ = formal
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 9e36998

Please sign in to comment.