Skip to content

Commit

Permalink
fix nim-lang#13182: proc fun(a: varargs[Foo, conv]) now can be over…
Browse files Browse the repository at this point in the history
…loaded
  • Loading branch information
timotheecour committed Feb 7, 2020
1 parent bf3f1c3 commit 337fbd0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,8 @@ proc localConvMatch(c: PContext, m: var TCandidate, f, a: PType,
var call = newNodeI(nkCall, arg.info)
call.add(f.n.copyTree)
call.add(arg.copyTree)
result = c.semExpr(c, call)
result = c.semTryExpr(c, call)

if result != nil:
if result.typ == nil: return nil
# resulting type must be consistent with the other arguments:
Expand Down
47 changes: 47 additions & 0 deletions tests/errmsgs/tsigmatch2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
discard """
cmd: "nim check --showAllMismatches:on --hints:off $file"
nimout: '''
tsigmatch2.nim(40, 14) Error: type mismatch: got <float64>
but expected one of:
proc foo(i: Foo): string
first type mismatch at position: 1
required type for i: Foo
but expression '1.2' is of type: float64
proc foo(args: varargs[string, myproc]): string
first type mismatch at position: 1
required type for args: varargs[string]
but expression '1.2' is of type: float64
expression: foo(1.2)
tsigmatch2.nim(46, 7) Error: type mismatch: got <int literal(1)>
but expected one of:
proc foo(args: varargs[string, myproc])
first type mismatch at position: 1
required type for args: varargs[string]
but expression '1' is of type: int literal(1)
expression: foo 1
'''
errormsg: "type mismatch"
"""



# line 30

block: # issue #13182
proc myproc(a: int): string = $("myproc", a)
proc foo(args: varargs[string, myproc]): string = $args
type Foo = object
proc foo(i: Foo): string = "in foo(i)"
static: doAssert foo(Foo()) == "in foo(i)"
static: doAssert foo(1) == """["(\"myproc\", 1)"]"""
doAssert not compiles(foo(1.2))
discard foo(1.2)

block:
proc myproc[T](x: T): string =
let temp = 12.isNil
proc foo(args: varargs[string, myproc]) = discard
foo 1
static: echo "done"

0 comments on commit 337fbd0

Please sign in to comment.