Skip to content

Commit

Permalink
revert a little bit, fix distinct types in static instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Aug 22, 2024
1 parent 8e2fc65 commit 7b29c2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 1 addition & 5 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,7 @@ proc semConv(c: PContext, n: PNode; flags: TExprFlags = {}, expectedType: PType
targetType = targetType.base
of tyAnything, tyUntyped, tyTyped:
localError(c.config, n.info, "illegal type conversion to '$1'" % typeToString(targetType))
elif c.inGenericContext > 0 and targetType.containsGenericType and
not (targetType.sym != nil and targetType.sym.magic != mNone):
result = semGenericStmt(c, n)
result.typ = makeTypeFromExpr(c, copyTree(result))
return
else: discard

maybeLiftType(targetType, c, n[0].info)

Expand Down
1 change: 1 addition & 0 deletions compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
if not cl.allowMetaTypes and result.n != nil and
result.base.kind != tyNone:
result.n = cl.c.semConstExpr(cl.c, result.n)
result.n.typ = result.base

of tyGenericInst, tyUserTypeClassInst:
bailout()
Expand Down
9 changes: 8 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
of tyFromExpr:
# fix the expression, so it contains the already instantiated types
if f.n == nil or f.n.kind == nkEmpty: return isGeneric
if c.c.inGenericContext > 0:
# need to delay until instantiation
# also prevent infinite recursion below
return isNone
inc c.c.inGenericContext # to generate tyFromExpr again if unresolved
let reevaluated = tryResolvingStaticExpr(c, f.n, allowCalls = true).typ
dec c.c.inGenericContext
Expand Down Expand Up @@ -2180,7 +2184,10 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
return argSemantized

if a.kind == tyStatic:
discard
if m.callee.kind == tyGenericBody and
a.n == nil and
tfGenericTypeParam notin a.flags:
return newNodeIT(nkType, argOrig.info, makeTypeFromExpr(c, arg))
elif arg.kind != nkEmpty:
var evaluated = c.semTryConstExpr(c, arg)
if evaluated != nil:
Expand Down

0 comments on commit 7b29c2b

Please sign in to comment.