Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code that used `multi` aspect of multimethod now crashes at runtime #10912

Closed
nc-x opened this issue Mar 27, 2019 · 0 comments

Comments

Projects
None yet
4 participants
@nc-x
Copy link
Contributor

commented Mar 27, 2019

type
  X = ref object of RootObj
  
type
  A* = ref object of RootObj
  B* = ref object of A
  C* = ref object of A
  D* = ref object of A
  E* = ref object of A
  F* = ref object of A

method resolve(self: var X, stmt: A) {.base.} = discard

proc resolve*(self: var X, statements: seq[A]) =
  for statement in statements:
    resolve(self, statement)

method resolve(self: var X, stmt: B) =
  echo "hi"
method resolve(self: var X, stmt: C) =
  echo "hi"
method resolve(self: var X, stmt: D) =
  echo "hi"
method resolve(self: var X, stmt: E) =
  echo "hi"
method resolve(self: var X, stmt: F) =
  echo "hi"

var x = X()
var a = @[B(), C(), D(), E(), F()]
resolve(x, a)

crashes at runtime with -

t.nim(31)                t
t.nim(16)                resolve
t.nim(12)                resolve
fatal.nim(37)            sysFatal
Error: unhandled exception: invalid object conversion [ObjectConversionError]
Traceback (most recent call last)
t.nim(31)                t
t.nim(16)                resolve
t.nim(12)                resolve
fatal.nim(37)            sysFatal
SIGABRT: Abnormal termination.

IMO it would be better to give compile time error & suggestion to use --multimethods:on

@mratsim mratsim added the Regression label Mar 29, 2019

Araq added a commit that referenced this issue May 24, 2019

@Araq Araq closed this in ef8ddef May 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.