DEV Community

ringabout
ringabout

Posted on

Contribute to the Python-like Nim language

Progress

fixes the documentation of typeclasses

closes #21536; fixes manual.

The parser has been changed, now you need to use type RecordType = (tuple or object) ro declare types classes starting with tuple or object instead of type RecordType = tuple or object.

forbids using system.any for type conversions

fixes #14255; Crash in compiler when using system.any by accident.

var a = newSeq[bool](1000)
if any(a):
  echo "ok?"
Enter fullscreen mode Exit fullscreen mode

Now it gives proper an error message => "Error: illegal type conversion to 'any'".

fixes templates with untyped parameters resolve private fields wrongly in generics

fixes #3770; templates with untyped parameters resolve private fields wrongly in generics.

type
  Noice* = object
    hidden: int

template jjj*: Noice =
  Noice(hidden: 15)
Enter fullscreen mode Exit fullscreen mode
# bug #3770
import m3770

doAssert $jjj() == "(hidden: 15)"  # works

proc someGeneric(_: type) =
  doAssert $jjj() == "(hidden: 15)"

someGeneric(int)
Enter fullscreen mode Exit fullscreen mode

Now the example compiles.

(WIP) adds compiler support for object construction shorthand

WIP adds compiler support for object construction shorthand.

type
  Vector = object
    a: int = 999
    b, c: int

block: # positional construction
  ## It specifies all the unnamed fields
  var x = Vector(1, 2, 3)
  doAssert x.b == 2

block:
  ## unnamed fields can be mixed with named fields
  block:
    var x = Vector(a: 1, 2, 3)
    doAssert x.c == 3

  block:
    var x = Vector(1, b: 2, 3)
    doAssert x.c == 3

  block:
    var x = Vector(1, 2, c: 3)
    doAssert x.c == 3

block:
  ## Object variants support unnamed fields for tags, which should be known at the compile time.
  type
    Color = enum
      Red, Blue, Yellow
    Factor = object
      id: int
      case flag: Color
      of Red:
        num: int
      of Blue, Yellow:
        done: bool
      name: string

  block:
    var x = Factor(1, Red, 2, "1314")
    doAssert x.num == 2

  block:
    var x = Factor(1, Blue, true, "1314")
    doAssert x.done == true

  block:
    var x = Factor(1, Yellow, false, "1314")
    doAssert x.done == false


  type
    Ciao = object
      id: int
      case flag: bool = false
      of true:
        num: int
      of false:
        done: bool
      name: string

  block:
    var x = Ciao(12, false, false, "123")
    doAssert x.done == false

  block:
    var x = Ciao(12, flag: true, 1, "123")
    doAssert x.num == 1
Enter fullscreen mode Exit fullscreen mode

Weekly collection

https://forum.nim-lang.org/t/9908 (2/19)

https://forum.nim-lang.org/t/9940 (2/26)

https://forum.nim-lang.org/t/9970 (3/5)

https://forum.nim-lang.org/t/9989 (3/12)

https://forum.nim-lang.org/t/10024 (3/19)

Participating in contributions

Following The Roadmap 2023 for community building , you could join us in the matrix space where we discuss how to build a community. We appreciate doable suggestions and helps, such as improving the workflow, implementing the roadmap, suggesting doable tasks, reviewing code from contributors. United we stand. We shall work together to make the community thrive.

Sponsorship

Many thanks to Yepoleb, lenis0012, pietroppeter, Clonkk, mode80, Phil, CxPlanner, shirleyquirk, elcritch, geotre, thinkwelltwd, xrfez, enthus1ast, piertoni, Dnanilem, gemath for sponsoring me on GitHub.

Top comments (0)