mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 14:03:23 +00:00
This commit is contained in:
@@ -639,10 +639,10 @@ proc defaultNodeField(c: PContext, a: PNode, aTyp: PType): PNode =
|
||||
if child != nil:
|
||||
let node = newNode(nkIntLit)
|
||||
node.intVal = toInt64(lengthOrd(c.graph.config, aTypSkip))
|
||||
result = semExpr(c, newTree(nkCall, newSymNode(getCompilerProc(c.graph, "nimArrayWith"), a.info),
|
||||
semExprWithType(c, child),
|
||||
node
|
||||
))
|
||||
result = semExpr(c, newTree(nkCall, newSymNode(getSysSym(c.graph, a.info, "arrayWith"), a.info),
|
||||
semExprWithType(c, child),
|
||||
node
|
||||
))
|
||||
result.typ = aTyp
|
||||
elif aTypSkip.kind == tyTuple:
|
||||
var hasDefault = false
|
||||
|
||||
@@ -2801,7 +2801,10 @@ when notJSnotNims and not defined(nimSeqsV2):
|
||||
assert y == "abcgh"
|
||||
discard
|
||||
|
||||
proc nimArrayWith[T](y: T, size: static int): array[size, T] {.compilerRtl, raises: [].} =
|
||||
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:
|
||||
result[i] = y
|
||||
when nimvm:
|
||||
result[i] = y
|
||||
else:
|
||||
result[i] = `=dup`(y)
|
||||
|
||||
@@ -688,6 +688,20 @@ template main {.dirty.} =
|
||||
else:
|
||||
testAssignResult()
|
||||
|
||||
block: # bug #22123
|
||||
type Thing = object
|
||||
x: float32 = 1
|
||||
|
||||
type ThingWithArray = object
|
||||
arr: array[256, float32]
|
||||
n: float32 = 1
|
||||
|
||||
type Container = ref object
|
||||
thing: array[5, Thing]
|
||||
thing_with_array: array[5, ThingWithArray]
|
||||
|
||||
var foo = new Container
|
||||
doAssert int(foo.thing[0].x) == 1
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user