Skip to content

Nil error not catched on compile time #7248

@alehander92

Description

@alehander92
type
  Style = ref object
    color: int

proc f*(style: Style) =
  if not style.isNil:
    echo style.color
  else:
    echo style.color

f(Style(color: 2))
f(nil)

I expect that f wouldn't be able to compile, as it's obvious that its fields are inaccessible in the else branch.

Nim can already prove a lot of nil related errors, so catching those should be a good step forward for type safety (nil runtime errors are obviously a very serious problem)

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