Skip to content

Commit

Permalink
fixes nim-lang#20883; Unspecified generic on default value segfaults …
Browse files Browse the repository at this point in the history
…the compiler (nim-lang#20917)

test CI
  • Loading branch information
ringabout authored Dec 1, 2022
1 parent 8266750 commit 10b6e4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type
info*: TLineInfo
allowMetaTypes*: bool # allow types such as seq[Number]
# i.e. the result contains unresolved generics
fromStaticExpr*: bool
skipTypedesc*: bool # whether we should skip typeDescs
isReturnType*: bool
owner*: PSym # where this instantiation comes from
Expand Down Expand Up @@ -238,6 +239,8 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0): PNode =
assert result.kind notin nkCallKinds
else:
if n.len > 0:
if n.kind in nkCallKinds and n[0].kind == nkIdent and cl.fromStaticExpr:
localError(cl.c.config, n.info, "An unresolved call in staticExpr: '" & renderTree(n) & "'")
newSons(result, n.len)
if start > 0:
result[0] = n[0]
Expand Down Expand Up @@ -660,10 +663,11 @@ proc initTypeVars*(p: PContext, typeMap: LayeredIdTable, info: TLineInfo;
result.owner = owner

proc replaceTypesInBody*(p: PContext, pt: TIdTable, n: PNode;
owner: PSym, allowMetaTypes = false): PNode =
owner: PSym, allowMetaTypes = false, fromStaticExpr = false): PNode =
var typeMap = initLayeredTypeMap(pt)
var cl = initTypeVars(p, typeMap, n.info, owner)
cl.allowMetaTypes = allowMetaTypes
cl.fromStaticExpr = fromStaticExpr
pushInfoContext(p.config, n.info)
result = replaceTypeVarsN(cl, n)
popInfoContext(p.config)
Expand Down
3 changes: 2 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@ proc tryResolvingStaticExpr(c: var TCandidate, n: PNode,
# N is bound to a concrete value during the matching of the first param.
# This proc is used to evaluate such static expressions.
let instantiated = replaceTypesInBody(c.c, c.bindings, n, nil,
allowMetaTypes = allowUnresolved)
allowMetaTypes = allowUnresolved,
fromStaticExpr = true)
result = c.c.semExpr(c.c, instantiated)

proc inferStaticParam*(c: var TCandidate, lhs: PNode, rhs: BiggestInt): bool =
Expand Down

0 comments on commit 10b6e4f

Please sign in to comment.