summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semexprs.nim10
-rw-r--r--tests/converter/texplicit_conversion.nim13
2 files changed, 17 insertions, 6 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 9f0696252..d76bd791e 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -191,10 +191,6 @@ proc semConv(c: PContext, n: PNode): PNode =
     case status
     of convOK:
       # handle SomeProcType(SomeGenericProc)
-      # XXX: This needs fixing. checkConvertible uses typeRel internally, but
-      # doesn't bother to perform the work done in paramTypeMatchAux/fitNode
-      # so we are redoing the typeRel work here. Why does semConv exist as a
-      # separate proc from fitNode?
       if op.kind == nkSym and op.sym.isGenericRoutine:
         result.sons[1] = fitNode(c, result.typ, result.sons[1])
       elif op.kind == nkPar and targetType.kind == tyTuple:
@@ -202,8 +198,10 @@ proc semConv(c: PContext, n: PNode): PNode =
     of convNotNeedeed:
       message(n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString)
     of convNotLegal:
-      localError(n.info, errGenerated, msgKindToString(errIllegalConvFromXtoY)%
-        [op.typ.typeToString, result.typ.typeToString])
+      result = fitNode(c, result.typ, result.sons[1])
+      if result == nil:
+        localError(n.info, errGenerated, msgKindToString(errIllegalConvFromXtoY)%
+          [op.typ.typeToString, result.typ.typeToString])
   else:
     for i in countup(0, sonsLen(op) - 1):
       let it = op.sons[i]
diff --git a/tests/converter/texplicit_conversion.nim b/tests/converter/texplicit_conversion.nim
new file mode 100644
index 000000000..16de62a57
--- /dev/null
+++ b/tests/converter/texplicit_conversion.nim
@@ -0,0 +1,13 @@
+discard """
+  output: "234"
+"""
+
+# bug #4461
+
+import strutils
+
+converter toInt(s: string): int =
+  result = parseInt(s)
+
+let x = (int)"234"
+echo x