Skip to content

Commit 0864216

Browse files
authored
build typeArgs for explicit generics (#566)
* build typeArgs for explicit generics * wrong merge * unneeded diff
1 parent 3782f78 commit 0864216

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/nimony/sem.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3357,7 +3357,7 @@ proc semExprSym(c: var SemContext; it: var Item; s: Sym; start: int; flags: set[
33573357
c.buildErr it.n.info, "undeclared identifier", cursorAt(orig, 0)
33583358
it.typ = c.types.autoType
33593359
elif s.kind == CchoiceY:
3360-
if AllowOverloads notin flags and c.routine.kind != TemplateY:
3360+
if KeepMagics notin flags and c.routine.kind != TemplateY:
33613361
c.buildErr it.n.info, "ambiguous identifier"
33623362
it.typ = c.types.autoType
33633363
elif s.kind in {TypeY, TypevarY}:
@@ -4580,6 +4580,7 @@ proc tryExplicitRoutineInst(c: var SemContext; syms: Cursor; it: var Item): bool
45804580
var m = createMatch(addr c)
45814581
m.fn = candidate
45824582
matchTypevars m, candidate, args
4583+
buildTypeArgs(m)
45834584
if not m.err:
45844585
# match
45854586
c.dest.add symToken(sym, syms.info)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
proc importedGeneric*[T](x: T): T =
2+
result = x
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
(.nif24)
2+
0,1,tests/nimony/generics/texplicitprocinst.nim(stmts
3+
(proc 5 :foo.0.texhjoap . . 8
4+
(typevars 1
5+
(typevar :T.0.texhjoap . . . .)) 11
6+
(params 1
7+
(param :x.0 . . 3 T.0.texhjoap .)) . . . 20
8+
(stmts
9+
(discard .))) ,1
10+
(proc 5 :foo.1.texhjoap . . 8
11+
(typevars 1
12+
(typevar :T.1.texhjoap . . . .) 4
13+
(typevar :U.0.texhjoap . . . .)) 14
14+
(params 1
15+
(param :x.1 . . 3 T.1.texhjoap .) 7
16+
(param :y.0 . . 3 U.0.texhjoap .)) . . . 29
17+
(stmts
18+
(discard .))) ,3
19+
(discard 8 foo.2.texhjoap) ,4
20+
(discard 8 foo.3.texhjoap) 8,5
21+
(call ~8 foo.2.texhjoap 1 +123) 16,6
22+
(call ~16 foo.3.texhjoap 1 +123 6 "abc") ,10
23+
(discard 28
24+
(call ~20 importedGeneric.0.texhjoap 1 +123)) 8,3
25+
(proc :foo.2.texhjoap . ~8,~3 .
26+
(at foo.0.texhjoap 4
27+
(i -1)) 3,~3
28+
(params 1
29+
(param :x.5 . . ,3
30+
(i -1) .)) ~8,~3 . ~8,~3 . ~8,~3 . 12,~3
31+
(stmts
32+
(discard .))) 8,4
33+
(proc :foo.3.texhjoap . ~8,~3 .
34+
(at foo.1.texhjoap 4,~1
35+
(i -1) 9 string.0.sys9azlf) 6,~3
36+
(params 1
37+
(param :x.6 . . ~3,2
38+
(i -1) .) 7
39+
(param :y.2 . . ~4,3 string.0.sys9azlf .)) ~8,~3 . ~8,~3 . ~8,~3 . 21,~3
40+
(stmts
41+
(discard .))) 28,10
42+
(proc :importedGeneric.0.texhjoap . 0,1,tests/nimony/generics/deps/mgenericproc.nim .
43+
(at importedGeneric.0.mgesx53wa1
44+
(i -1)) 24,1,tests/nimony/generics/deps/mgenericproc.nim
45+
(params 1
46+
(param :x.7 . .
47+
(i -1) .))
48+
(i -1) 0,1,tests/nimony/generics/deps/mgenericproc.nim . 0,1,tests/nimony/generics/deps/mgenericproc.nim . 2,2,tests/nimony/generics/deps/mgenericproc.nim
49+
(stmts 7
50+
(result :result.0 . .
51+
(i -1) .) 7
52+
(asgn ~7 result.0 2 x.7) ~2,~1
53+
(ret result.0))))

tests/nimony/generics/texplicitprocinst.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ discard foo[int]
55
discard foo[int, string]
66
foo[int](123)
77
foo[int, string](123, "abc")
8+
9+
import deps/mgenericproc
10+
11+
discard importedGeneric[int](123)

0 commit comments

Comments
 (0)