mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes #24773
`c.inheritancePenalty` is supposed to be used for the entire match, but
in these places the inheritance penalty of a single argument overrides
the entire match penalty. The `+ ord(c.inheritancePenalty < 0)` is
copied from other places that use the same idiom, the intent is that the
existing penalty changes from -1 to 0 first to mark that it participates
in inheritance before adding the inheritance depth.
---------
Co-authored-by: Andreas Rumpf <araq4k@proton.me>
(cherry picked from commit fb93295344)
27 lines
304 B
Nim
27 lines
304 B
Nim
# issue #24773
|
|
|
|
import std/assertions
|
|
|
|
type
|
|
A {.inheritable.} = object
|
|
B = object of A
|
|
C = object of B
|
|
|
|
proc add1(v: B) =
|
|
doAssert true
|
|
|
|
proc add1(v: A) =
|
|
doAssert false
|
|
|
|
proc add2(v: B, v2: A) =
|
|
doAssert true
|
|
|
|
proc add2(v: A, v2: A) =
|
|
doAssert false
|
|
|
|
var x: C
|
|
var y: B
|
|
|
|
add1(x)
|
|
add2(x, y)
|