diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index df094402c..95f5f0b07 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1031,6 +1031,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = if x < isSubtype: return isNone # 'and' implies minimum matching result: if x < result: result = x + if result > isGeneric: result = isGeneric bindingRet result of tyOr: @@ -1041,6 +1042,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = # 'or' implies maximum matching result: if x > result: result = x if result >= isSubtype: + if result > isGeneric: result = isGeneric bindingRet result else: result = isNone diff --git a/tests/converter/tor_in_converter.nim b/tests/converter/tor_in_converter.nim new file mode 100644 index 000000000..5674526a1 --- /dev/null +++ b/tests/converter/tor_in_converter.nim @@ -0,0 +1,23 @@ +discard """ + output: '''test +test''' +""" +# bug #4537 + +# nim js --d:nodejs + +type + Str = distinct string + +when true: + # crashes + converter convert(s: string | cstring): Str = Str($s) +else: + # works! + converter convert(s: string): Str = Str($s) + converter convert(s: cstring): Str = Str($s) + +proc echoStr(s: Str) = echo s.string + +echoStr("test") +echoStr("test".cstring)