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

[regression] dynamic dispatch on multiple arguments crashes compiler #8246

Closed
skilchen opened this issue Jul 8, 2018 · 2 comments
Closed

Comments

@skilchen
Copy link
Contributor

skilchen commented Jul 8, 2018

This program can't be compiled with the latest devel version of Nim:

type
  Foo = object of RootObj
  Bar = object of Foo
    x: int

method mm(a: Foo, b: Foo) {.base.} =
  echo "mm: Foo, Foo"    

method mm(a: Bar, b: Bar)  =
  echo "mm: Bar, Bar"
  
method mm(a: Foo, b: Bar)  =
  echo "mm: Foo, Bar"
  
method mm(a: Bar, b: Foo)  =
  echo "mm: Bar, Foo"

proc test() =
  var foo: Foo
  var bar: Bar

  mm(foo, foo)
  mm(foo, bar)
  mm(bar, foo)
  mm(bar, bar)

test()

This issue is related to the fact that currently the CI tests fail.

The very surprising and slightly disturbing fact is: this issue is caused by the line {.deprecated: [SomeReal: SomeFloat].} in system.nim.

Without this deprecation, the test-program compiles and runs correctly and so do the currently failing tests method\tmultim2 and method\tmultim6

LemonBoy added a commit to LemonBoy/Nim that referenced this issue Jul 8, 2018
Using getSysSym made the compiler pick a random `and` symbol: if the
symbol table is shuffled we may end up selecting one of the wrong
overloads.

Fixes nim-lang#8246
@Araq Araq closed this as completed in #8249 Jul 8, 2018
Araq pushed a commit that referenced this issue Jul 8, 2018
Using getSysSym made the compiler pick a random `and` symbol: if the
symbol table is shuffled we may end up selecting one of the wrong
overloads.

Fixes #8246
@timotheecour
Copy link
Member

@LemonBoy indeed, I was seeing unrelated failures :

https://travis-ci.org/nim-lang/Nim/jobs/401284582
#8213

FAIL: tmultim2.nim C
Test "tests/method/tmultim2.nim" in category "method"
Failure: reNimcCrash
Expected:
Gotten:
internal error: genMagicExpr: mTypeTrait


FAIL: tmultim6.nim C
Test "tests/method/tmultim6.nim" in category "method"
Failure: reNimcCrash
Expected:
Gotten:
internal error: genMagicExpr: mTypeTrait

hopefully the PR fixed it, but, curious how this regression was even possible; wouldn't have that failing test prevented the PR that introduced the bug from being green? or was it a flaky failure?

@LemonBoy
Copy link
Contributor

curious how this regression was even possible

Luck. Every time the system.nim was modified the compiler would pick one of the three and overloads (mAnd, mBitandI, mTypeTrait) but it was lucky enough to pick one of the first two that work fine with bools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants