Skip to content

Commit 79ec8c2

Browse files
authored
fix #13182: proc fun(a: varargs[Foo, conv]) now can be overloaded (#13345) [backport]
1 parent c0a2e2e commit 79ec8c2

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

compiler/sigmatch.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,8 @@ proc localConvMatch(c: PContext, m: var TCandidate, f, a: PType,
19381938
var call = newNodeI(nkCall, arg.info)
19391939
call.add(f.n.copyTree)
19401940
call.add(arg.copyTree)
1941-
result = c.semExpr(c, call)
1941+
result = c.semTryExpr(c, call)
1942+
19421943
if result != nil:
19431944
if result.typ == nil: return nil
19441945
# resulting type must be consistent with the other arguments:

tests/errmsgs/tsigmatch2.nim

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
discard """
2+
cmd: "nim check --showAllMismatches:on --hints:off $file"
3+
nimout: '''
4+
tsigmatch2.nim(40, 14) Error: type mismatch: got <float64>
5+
but expected one of:
6+
proc foo(i: Foo): string
7+
first type mismatch at position: 1
8+
required type for i: Foo
9+
but expression '1.2' is of type: float64
10+
proc foo(args: varargs[string, myproc]): string
11+
first type mismatch at position: 1
12+
required type for args: varargs[string]
13+
but expression '1.2' is of type: float64
14+
15+
expression: foo(1.2)
16+
tsigmatch2.nim(46, 7) Error: type mismatch: got <int literal(1)>
17+
but expected one of:
18+
proc foo(args: varargs[string, myproc])
19+
first type mismatch at position: 1
20+
required type for args: varargs[string]
21+
but expression '1' is of type: int literal(1)
22+
23+
expression: foo 1
24+
'''
25+
errormsg: "type mismatch"
26+
"""
27+
28+
29+
30+
# line 30
31+
32+
block: # issue #13182
33+
proc myproc(a: int): string = $("myproc", a)
34+
proc foo(args: varargs[string, myproc]): string = $args
35+
type Foo = object
36+
proc foo(i: Foo): string = "in foo(i)"
37+
static: doAssert foo(Foo()) == "in foo(i)"
38+
static: doAssert foo(1) == """["(\"myproc\", 1)"]"""
39+
doAssert not compiles(foo(1.2))
40+
discard foo(1.2)
41+
42+
block:
43+
proc myproc[T](x: T): string =
44+
let temp = 12.isNil
45+
proc foo(args: varargs[string, myproc]) = discard
46+
foo 1
47+
static: echo "done"

0 commit comments

Comments
 (0)