summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBung <crc32@qq.com>2022-10-11 17:42:49 +0800
committerGitHub <noreply@github.com>2022-10-11 11:42:49 +0200
commit083ea8f10cb27834cc9c22ba496de7a378f3c301 (patch)
tree4913455e2df4901524783bfa903d1722524ca5d7
parent5602183234f59ece4fd668915da848f0753cbbb9 (diff)
downloadNim-083ea8f10cb27834cc9c22ba496de7a378f3c301.tar.gz
fix #7446 Generics: type mismatch 'SomeunsignedInt or Natural' (#20522)
* fix #7446 Generics: type mismatch 'SomeunsignedInt or Natural'

* try fix
-rw-r--r--compiler/sigmatch.nim3
-rw-r--r--tests/generics/t7446.nim10
2 files changed, 11 insertions, 2 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 5448d8dcd..60b0fe612 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1595,10 +1595,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
         c.inheritancePenalty = 0
         let x = typeRel(c, branch, aOrig, flags)
         maxInheritance = max(maxInheritance, c.inheritancePenalty)
-
         # 'or' implies maximum matching result:
         if x > result: result = x
-      if result >= isSubtype:
+      if result >= isIntConv:
         if result > isGeneric: result = isGeneric
         bindingRet result
       else:
diff --git a/tests/generics/t7446.nim b/tests/generics/t7446.nim
new file mode 100644
index 000000000..71aa8f0e8
--- /dev/null
+++ b/tests/generics/t7446.nim
@@ -0,0 +1,10 @@
+proc foo(x: Natural or SomeUnsignedInt):int = 
+  when x is int:
+    result = 1
+  else:
+    result = 2
+let a = 10
+doAssert foo(a) == 1
+
+let b = 10'u8
+doAssert foo(b) == 2
\ No newline at end of file