Skip to content

Commit

Permalink
fix nim-lang#7446 Generics: type mismatch 'SomeunsignedInt or Natural' (
Browse files Browse the repository at this point in the history
nim-lang#20522)

* fix nim-lang#7446 Generics: type mismatch 'SomeunsignedInt or Natural'

* try fix
  • Loading branch information
bung87 authored and capocasa committed Mar 31, 2023
1 parent 102c36a commit bc1b873
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions tests/generics/t7446.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bc1b873

Please sign in to comment.