summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-09-26 20:05:18 +0800
committerGitHub <noreply@github.com>2023-09-26 14:05:18 +0200
commita7a0cfe8eb5942d799b4b7e2fdf26bcb9ff8ffab (patch)
treeccf638c5622e6d9f136c3acc6a9cff11eab369d7
parent435f9320889f21269a26a17f724b73c4a46f9f23 (diff)
downloadNim-a7a0cfe8eb5942d799b4b7e2fdf26bcb9ff8ffab.tar.gz
fixes #10542; suppresses varargs conversion warnings (#22757)
fixes #10542
revives and close #20169
-rw-r--r--compiler/semexprs.nim3
-rw-r--r--compiler/sigmatch.nim2
-rw-r--r--tests/errmsgs/t10542.nim24
3 files changed, 27 insertions, 2 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 590d2610b..633a0cc26 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -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:
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 1cf29dcfd..ee93321c8 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -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
diff --git a/tests/errmsgs/t10542.nim b/tests/errmsgs/t10542.nim
new file mode 100644
index 000000000..b57dbf18b
--- /dev/null
+++ b/tests/errmsgs/t10542.nim
@@ -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")
\ No newline at end of file