Skip to content

Commit

Permalink
Fixes #24369 (#24370)
Browse files Browse the repository at this point in the history
Hope this fixes #24369, happy for any feedback on the PR.
  • Loading branch information
saemideluxe authored Nov 10, 2024
1 parent 3e47725 commit 1fddb61
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
5 changes: 3 additions & 2 deletions compiler/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 10 additions & 0 deletions tests/system/tcopyprotected_arrayinit.nim
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 1fddb61

Please sign in to comment.