mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 00:41:28 +00:00
make var object match better than object (#22152)
* fix `var object` not matching better than `object`
fixes #13302
* remove comment for brevity
* try note
* try minimize breaks
(cherry picked from commit 20037a4749)
This commit is contained in:
@@ -211,7 +211,7 @@ proc sumGeneric(t: PType): int =
|
||||
# and Foo[T] has the value 2 so that we know Foo[Foo[T]] is more
|
||||
# specific than Foo[T].
|
||||
var t = t
|
||||
var isvar = 1
|
||||
var isvar = 0
|
||||
while true:
|
||||
case t.kind
|
||||
of tyGenericInst, tyArray, tyRef, tyPtr, tyDistinct, tyUncheckedArray,
|
||||
@@ -247,6 +247,8 @@ proc sumGeneric(t: PType): int =
|
||||
of tyBool, tyChar, tyEnum, tyObject, tyPointer,
|
||||
tyString, tyCstring, tyInt..tyInt64, tyFloat..tyFloat128,
|
||||
tyUInt..tyUInt64, tyCompositeTypeClass:
|
||||
return isvar + 1
|
||||
of tyBuiltInTypeClass:
|
||||
return isvar
|
||||
else:
|
||||
return 0
|
||||
|
||||
11
tests/overload/tvartypeclass.nim
Normal file
11
tests/overload/tvartypeclass.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
# issue #13302
|
||||
|
||||
proc foo(x: object): int = x.i*2
|
||||
proc foo(x: var object) = x.i*=2
|
||||
type Foo = object
|
||||
i: int
|
||||
let x = Foo(i: 3)
|
||||
var y = Foo(i: 4)
|
||||
doAssert foo(x) == 6
|
||||
foo(y)
|
||||
doAssert y.i == 8
|
||||
Reference in New Issue
Block a user