Skip to content

Unable to make a const instance of an inherited, generic object. #11268

@linkmonitor

Description

@linkmonitor

Compilation fails when it includes a const instance of an object inherited from a generic object.

Example

type
  Point1[T] = object of RootObj
    x:T

  Point2[T] = object of Point1[T]
    y:T

proc main =
  var a = Point2[int](x:1, y:2)
  echo a

  let b = Point2[int](x:1, y:2)
  echo b

  const c = Point2[int](x:1, y:2)
  echo c

when isMainModule:
  main()

Current Output

main.nim(15, 24) Error: cannot create null element for: [T]

Expected Output

(y: 2, x: 1)
(y: 2, x: 1)
(y: 2, x: 1)

Additional Information

Updated my toolchain using choosenim approximately 6 hours ago.

$ nim -v
Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-05-16
Copyright (c) 2006-2019 by Andreas Rumpf

active boot switches: -d:release

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions