From 1ddd2a3865cbea7378a1f14575ea49766a54c0ab Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 29 Jul 2016 00:58:39 +0200 Subject: [PATCH] fixes #4432 --- compiler/semexprs.nim | 10 ++++------ tests/converter/texplicit_conversion.nim | 13 +++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 tests/converter/texplicit_conversion.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 9f0696252c..d76bd791ee 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 0000000000..16de62a575 --- /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