mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-24 08:15:25 +00:00
Merge pull request #2856 from fowlmouth/patch-4
made string compatible with openarray[char]
This commit is contained in:
@@ -748,6 +748,12 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
|||||||
result = isConvertible
|
result = isConvertible
|
||||||
elif typeRel(c, base(f), a.sons[0]) >= isGeneric:
|
elif typeRel(c, base(f), a.sons[0]) >= isGeneric:
|
||||||
result = isConvertible
|
result = isConvertible
|
||||||
|
of tyString:
|
||||||
|
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
|
else: discard
|
||||||
of tySequence:
|
of tySequence:
|
||||||
case a.kind
|
case a.kind
|
||||||
|
|||||||
22
tests/typerel/tstr_as_openarray.nim
Normal file
22
tests/typerel/tstr_as_openarray.nim
Normal file
@@ -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"
|
||||||
Reference in New Issue
Block a user