From 3601bb81c96bd3ded928a680dccfcfed125692f9 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 13 Apr 2023 18:11:06 +0800 Subject: [PATCH] fixes #20900; Calling template through from generic function across module fails to build (#21649) * fixes #20900; Calling template through from generic function across module fails to build * sanother way (cherry picked from commit 16f42084d32144d5afb2a5cc3a5a833e5295a8bc) --- compiler/semobjconstr.nim | 1 + tests/generics/m3770.nim | 9 +++++++-- tests/generics/t3770.nim | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim index eb9b2edad3..3ef1ca7ac2 100644 --- a/compiler/semobjconstr.nim +++ b/compiler/semobjconstr.nim @@ -82,6 +82,7 @@ proc semConstrField(c: PContext, flags: TExprFlags, var initValue = semExprFlagDispatched(c, assignment[1], flags, field.typ) if initValue != nil: initValue = fitNodeConsiderViewType(c, field.typ, initValue, assignment.info) + initValue.flags.incl nfSkipFieldChecking assignment[0] = newSymNode(field) assignment[1] = initValue assignment.flags.incl nfSem diff --git a/tests/generics/m3770.nim b/tests/generics/m3770.nim index 2c6a2bd113..7f5714a2b1 100644 --- a/tests/generics/m3770.nim +++ b/tests/generics/m3770.nim @@ -1,6 +1,11 @@ type Noice* = object hidden: int - + template jjj*: Noice = - Noice(hidden: 15) \ No newline at end of file + Noice(hidden: 15) + +type Opt* = object + o: int + +template none*(O: type Opt): Opt = Opt(o: 0) diff --git a/tests/generics/t3770.nim b/tests/generics/t3770.nim index fa9c97df83..ffccbeeb55 100644 --- a/tests/generics/t3770.nim +++ b/tests/generics/t3770.nim @@ -7,3 +7,7 @@ proc someGeneric(_: type) = doAssert $jjj() == "(hidden: 15)" # fails: "Error: the field 'hidden' is not accessible." someGeneric(int) + +# bug #20900 +proc c(y: int | int, w: Opt = Opt.none) = discard +c(0)