mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
Hope this fixes #24369, happy for any feedback on the PR.
This commit is contained in:
@@ -671,8 +671,9 @@ proc defaultNodeField(c: PContext, a: PNode, aTyp: PType, checkDefault: bool): P
|
||||
if child != nil:
|
||||
let node = newNode(nkIntLit)
|
||||
node.intVal = toInt64(lengthOrd(c.graph.config, aTypSkip))
|
||||
result = semExpr(c, newTree(nkCall, newSymNode(getSysSym(c.graph, a.info, "arrayWith"), a.info),
|
||||
semExprWithType(c, child),
|
||||
let typeNode = newNode(nkType)
|
||||
typeNode.typ() = makeTypeDesc(c, aTypSkip[1])
|
||||
result = semExpr(c, newTree(nkCall, newTree(nkBracketExpr, newSymNode(getSysSym(c.graph, a.info, "arrayWithDefault"), a.info), typeNode),
|
||||
node
|
||||
))
|
||||
result.typ() = aTyp
|
||||
|
||||
@@ -2966,8 +2966,9 @@ when notJSnotNims and not defined(nimSeqsV2):
|
||||
proc arrayWith*[T](y: T, size: static int): array[size, T] {.raises: [].} =
|
||||
## Creates a new array filled with `y`.
|
||||
for i in 0..size-1:
|
||||
when nimvm:
|
||||
result[i] = y
|
||||
else:
|
||||
# TODO: fixme it should be `=dup`
|
||||
result[i] = y
|
||||
result[i] = y
|
||||
|
||||
proc arrayWithDefault*[T](size: static int): array[size, T] {.raises: [].} =
|
||||
## Creates a new array filled with `default(T)`.
|
||||
for i in 0..size-1:
|
||||
result[i] = default(T)
|
||||
|
||||
10
tests/system/tcopyprotected_arrayinit.nim
Normal file
10
tests/system/tcopyprotected_arrayinit.nim
Normal file
@@ -0,0 +1,10 @@
|
||||
type
|
||||
Bar = object
|
||||
b: int = 1
|
||||
|
||||
Foo = object
|
||||
f: array[1, Bar]
|
||||
|
||||
proc `=copy`(dest: var Bar, source: Bar) {.error.}
|
||||
|
||||
discard Foo()
|
||||
Reference in New Issue
Block a user