Skip to content

Commit

Permalink
fixes #10542; suppresses varargs conversion warnings (#22757)
Browse files Browse the repository at this point in the history
fixes #10542
revives and close #20169
  • Loading branch information
ringabout committed Sep 26, 2023
1 parent 435f932 commit a7a0cfe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ proc semConv(c: PContext, n: PNode; flags: TExprFlags = {}, expectedType: PType
elif op.kind in {nkPar, nkTupleConstr} and targetType.kind == tyTuple:
op = fitNode(c, targetType, op, result.info)
of convNotNeedeed:
message(c.config, n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString)
if efNoSem2Check notin flags:
message(c.config, n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString)
of convNotLegal:
result = fitNode(c, result.typ, result[1], result.info)
if result == nil:
Expand Down
2 changes: 1 addition & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ proc localConvMatch(c: PContext, m: var TCandidate, f, a: PType,
if result != nil:
if result.typ == nil: return nil
# bug #13378, ensure we produce a real generic instantiation:
result = c.semExpr(c, call)
result = c.semExpr(c, call, {efNoSem2Check})
# resulting type must be consistent with the other arguments:
var r = typeRel(m, f[0], result.typ)
if r < isGeneric: return nil
Expand Down
24 changes: 24 additions & 0 deletions tests/errmsgs/t10542.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
discard """
matrix: "--hintaserror:ConvFromXtoItselfNotNeeded"
"""

# bug #10542

proc f(args: varargs[string, string], length: int) =
doAssert args.len == length

# main use case that requires type conversion (no warning here)
f("a", "b", 2)
f("a", 1)


proc m(args: varargs[cstring, cstring]) =
doAssert args.len == 2

# main use case that requires type conversion (no warning here)
m("a", "b")

# if an argument already is cstring there's a warning
let x: cstring = "x"
m("a", x)
m(x, "a")

0 comments on commit a7a0cfe

Please sign in to comment.