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
bung authored and bung committed May 25, 2023
1 parent a8718d8 commit b18fef7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ proc explicitGenericInstError(c: PContext; n: PNode): PNode =
proc explicitGenericSym(c: PContext, n: PNode, s: PSym): PNode =
# binding has to stay 'nil' for this to work!
var m = newCandidate(c, s, nil)

inc c.inExplicitGenericSym
for i in 1..<n.len:
let formal = s.ast[genericParamsPos][i-1].typ
var arg = n[i].typ
Expand All @@ -660,6 +660,7 @@ proc explicitGenericSym(c: PContext, n: PNode, s: PSym): PNode =
let info = getCallLineInfo(n)
markUsed(c, info, s)
onUse(info, s)
dec c.inExplicitGenericSym
result = newSymNode(newInst, info)

proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
Expand Down
1 change: 1 addition & 0 deletions compiler/semdata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type
compilesContextId*: int # > 0 if we are in a ``compiles`` magic
compilesContextIdGenerator*: int
inGenericInst*: int # > 0 if we are instantiating a generic
inExplicitGenericSym*: int
converters*: seq[PSym]
patterns*: seq[PSym] # sequence of pattern matchers
optionStack*: seq[POptionEntry]
Expand Down
3 changes: 2 additions & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,8 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode =
if s.astdef.safeLen == 0: result = inlineConst(c, n, s)
else: result = newSymNode(s, n.info)
of tyStatic:
if typ.n != nil:
let staticDuringGenericInst = (c.inStaticContext > 0 and c.inGenericInst > 0)
if (c.inExplicitGenericSym <= 0 or staticDuringGenericInst) and typ.n != nil:
result = typ.n
result.typ = typ.base
else:
Expand Down
16 changes: 16 additions & 0 deletions tests/generics/t10833.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type Foo*[A; B; C: static[int]] = object
s: string
# d: typeof(C)

proc build*[A; B; C: static[int]](s: string;): Foo[A, B, C] =
const d = 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 b18fef7

Please sign in to comment.