Hope this fixes #24369, happy for any feedback on the PR.
This commit is contained in:
Sam
2024-11-10 23:16:07 +07:00
committed by GitHub
parent 3e47725c08
commit 1fddb61b3b
3 changed files with 19 additions and 7 deletions

View File

@@ -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

View File

@@ -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)

View 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()