mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 06:18:51 +00:00
fixes openarray views default values in JS (#23607)
This commit is contained in:
@@ -1241,7 +1241,7 @@ proc needsNoCopy(p: PProc; y: PNode): bool =
|
||||
return y.kind in nodeKindsNeedNoCopy or
|
||||
((mapType(y.typ) != etyBaseIndex) and
|
||||
(skipTypes(y.typ, abstractInst).kind in
|
||||
{tyRef, tyPtr, tyLent, tyVar, tyCstring, tyProc, tyOwned} + IntegralTypes))
|
||||
{tyRef, tyPtr, tyLent, tyVar, tyCstring, tyProc, tyOwned, tyOpenArray} + IntegralTypes))
|
||||
|
||||
proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =
|
||||
var a, b: TCompRes = default(TCompRes)
|
||||
@@ -1966,7 +1966,7 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
|
||||
result = putToSeq("null", indirect)
|
||||
of tySequence, tyString:
|
||||
result = putToSeq("[]", indirect)
|
||||
of tyCstring, tyProc:
|
||||
of tyCstring, tyProc, tyOpenArray:
|
||||
result = putToSeq("null", indirect)
|
||||
of tyStatic:
|
||||
if t.n != nil:
|
||||
|
||||
15
tests/views/tviews2.nim
Normal file
15
tests/views/tviews2.nim
Normal file
@@ -0,0 +1,15 @@
|
||||
discard """
|
||||
targets: "c js"
|
||||
"""
|
||||
|
||||
{.experimental: "views".}
|
||||
|
||||
type
|
||||
Foo = object
|
||||
id: openArray[char]
|
||||
|
||||
proc foo(): Foo =
|
||||
var source = "1245"
|
||||
result = Foo(id: source.toOpenArray(0, 1))
|
||||
|
||||
doAssert foo().id == @['1', '2']
|
||||
Reference in New Issue
Block a user