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 16f42084d3)
This commit is contained in:
ringabout
2023-04-13 18:11:06 +08:00
committed by narimiran
parent 7142078707
commit 3601bb81c9
3 changed files with 12 additions and 2 deletions

View File

@@ -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

View File

@@ -1,6 +1,11 @@
type
Noice* = object
hidden: int
template jjj*: Noice =
Noice(hidden: 15)
Noice(hidden: 15)
type Opt* = object
o: int
template none*(O: type Opt): Opt = Opt(o: 0)

View File

@@ -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)