From f3b8a3cbbcee905eb6ed0b7268180b2d872eff7d Mon Sep 17 00:00:00 2001 From: Billingsly Wetherfordshire Date: Mon, 1 Jun 2015 06:04:22 -0500 Subject: [PATCH 1/3] made string compatible with openarray[char] --- compiler/sigmatch.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 7ea2c3d6f1..072890ddd7 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -748,6 +748,11 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = result = isConvertible elif typeRel(c, base(f), a.sons[0]) >= isGeneric: result = isConvertible + of tyString: + if f.sons[0].kind == tyChar: + result = isConvertible + elif f.sons[0].kind == tyGenericParam and typeRel(c, base(f), base(a)) >= isGeneric: + result = isConvertible else: discard of tySequence: case a.kind From 87c8d586b5955e8183b822016a3ebd2fcd0a821c Mon Sep 17 00:00:00 2001 From: Billingsly Wetherfordshire Date: Mon, 1 Jun 2015 07:37:36 -0500 Subject: [PATCH 2/3] string only matches for openarray not varargs --- compiler/sigmatch.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 072890ddd7..f506e3ff54 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -749,10 +749,11 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = elif typeRel(c, base(f), a.sons[0]) >= isGeneric: result = isConvertible of tyString: - if f.sons[0].kind == tyChar: - result = isConvertible - elif f.sons[0].kind == tyGenericParam and typeRel(c, base(f), base(a)) >= isGeneric: - result = isConvertible + if f.kind == tyOpenArray: + if f.sons[0].kind == tyChar: + result = isConvertible + elif f.sons[0].kind == tyGenericParam and typeRel(c, base(f), base(a)) >= isGeneric: + result = isConvertible else: discard of tySequence: case a.kind From 80a13a408e39ca197f42398163ef7917a64d1aad Mon Sep 17 00:00:00 2001 From: fowlmouth Date: Mon, 1 Jun 2015 11:01:50 -0500 Subject: [PATCH 3/3] added a test --- tests/typerel/tstr_as_openarray.nim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/typerel/tstr_as_openarray.nim diff --git a/tests/typerel/tstr_as_openarray.nim b/tests/typerel/tstr_as_openarray.nim new file mode 100644 index 0000000000..fc28d6c933 --- /dev/null +++ b/tests/typerel/tstr_as_openarray.nim @@ -0,0 +1,22 @@ +discard """ + output: '''success''' +""" +var s = "HI" + +proc x (zz: openarray[char]) = + discard + +x s + +proc z [T] (zz: openarray[T]) = + discard + +z s +z([s,s,s]) + +proc y [T] (arg: var openarray[T]) = + arg[0] = 'X' +y s +doAssert s == "XI" + +echo "success"