diff options
-rw-r--r-- | compiler/seminst.nim | 2 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 5 | ||||
-rw-r--r-- | tests/proc/tgenericdefaultparam.nim | 18 |
3 files changed, 25 insertions, 0 deletions
diff --git a/compiler/seminst.nim b/compiler/seminst.nim index ff1592573..1bc6d31a2 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -254,6 +254,8 @@ proc instantiateProcType(c: PContext, pt: TypeMapping, let needsStaticSkipping = resulti.kind == tyFromExpr let needsTypeDescSkipping = resulti.kind == tyTypeDesc and tfUnresolved in resulti.flags + if resulti.kind == tyFromExpr: + resulti.flags.incl tfNonConstExpr result[i] = replaceTypeVarsT(cl, resulti) if needsStaticSkipping: result[i] = result[i].skipTypes({tyStatic}) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 17d2e7a4d..a48e79b7c 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1279,6 +1279,11 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, if prev == nil: body else: return typeRel(c, prev, a, flags) + if c.c.inGenericContext > 0 and not c.isNoCall and + (tfUnresolved in a.flags or a.kind in tyTypeClasses): + # cheap check for unresolved arg, not nested + return isNone + case a.kind of tyOr: # XXX: deal with the current dual meaning of tyGenericParam diff --git a/tests/proc/tgenericdefaultparam.nim b/tests/proc/tgenericdefaultparam.nim index 2d0f850c2..7bce591ce 100644 --- a/tests/proc/tgenericdefaultparam.nim +++ b/tests/proc/tgenericdefaultparam.nim @@ -78,3 +78,21 @@ block: # issue #13270 g A() # This should fail because there is no f(a: B) overload available doAssert not compiles(g B()) + +block: # issue #24121 + type + Foo = distinct int + Bar = distinct int + FooBar = Foo | Bar + + proc foo[T: distinct](x: T): string = "a" + proc foo(x: Foo): string = "b" + proc foo(x: Bar): string = "c" + + proc bar(x: FooBar, y = foo(x)): string = y + doAssert bar(Foo(123)) == "b" + doAssert bar(Bar(123)) == "c" + + proc baz[T: FooBar](x: T, y = foo(x)): string = y + doAssert baz(Foo(123)) == "b" + doAssert baz(Bar(123)) == "c" |