diff options
author | metagn <metagngn@gmail.com> | 2023-06-25 17:52:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-25 16:52:16 +0200 |
commit | 20037a47499ea183afb0e8d2a3f68c2b2952aa5d (patch) | |
tree | 8746781536c41c4874c5a4892cdbd7c8d7fbb990 | |
parent | f718f295df3f6ee5d7fd6fc19e39ac663821b00a (diff) | |
download | Nim-20037a47499ea183afb0e8d2a3f68c2b2952aa5d.tar.gz |
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
-rw-r--r-- | compiler/sigmatch.nim | 4 | ||||
-rw-r--r-- | tests/overload/tvartypeclass.nim | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 5786a320c..f94b4ee60 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -215,7 +215,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, @@ -251,6 +251,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 diff --git a/tests/overload/tvartypeclass.nim b/tests/overload/tvartypeclass.nim new file mode 100644 index 000000000..04f3f5a91 --- /dev/null +++ b/tests/overload/tvartypeclass.nim @@ -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 |