Skip to content

Conversation

ringabout
Copy link
Member

fixes #25116

@ringabout
Copy link
Member Author

It's really annoying for range types though, I would expect tons of misusages of ranges

let z: seq[range['a'..'z']] = @['c']

Otherwise stdlibs need a requireInit typetraits for using zeroDefault for types requiring explicit initialization

@Araq
Copy link
Member

Araq commented Sep 11, 2025

The stdlib should use more zeroDefault then, why would it need yet another trait.

@ringabout
Copy link
Member Author

ringabout commented Sep 11, 2025

proc arrayWithDefault*[T](size: static int): array[size, T] {.noinit, nodestroy, raises: [].} =
  ## Creates a new array filled with `default(T)`.
  for i in 0..size-1:
    result[i] = default(T)


proc setLen[T](s: var seq[T], newlen: Natural) {.nodestroy.} =
  ...
  for i in oldLen..<newlen:
    xu.p.data[i] = default(T)

arrayWithDefault and setLen need default to set default values for objects with default value fields or ranges types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

default(T) breaks requiresInit requirements
2 participants