Skip to content

Make forward declaration unnecessary #5287

@simonkrauter

Description

@simonkrauter

I think the forward declaration for procs and methods should not be required in any case.
Working with Nim would be more convenient and less error-prone.

Example:

type T1 = ref object of RootObj
type T2 = ref object of T1
type T3 = ref object of T2

method m(self: T1) =
  echo "T1"

# method m(obj: T2) # forward declaration
  
method m(obj: T3) =
  procCall obj.T2.m()
  echo "T3"

method m(obj: T2) =
  procCall obj.T1.m()
  echo "T2"
  
var obj = T3()
obj.m()

In this example, a missing forward declaration leads to different/wrong program logic.
It still compiles fine, but the program result is not, what the programmer expect.
Would be nice, if this does the same with and without the forward declaration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions