Skip to content

Commit b10265c

Browse files
committed
clean up code
1 parent a627ae9 commit b10265c

1 file changed

Lines changed: 8 additions & 22 deletions

File tree

compiler/semtypes.nim

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,21 +1774,11 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
17741774
m.isNoCall = true
17751775
# `matches` proc can modify `n`.
17761776
# if there is a `tyForward` type in `n`, `matches` cannot work and modify `n` correctly.
1777-
# that case, add `prevN` to `c.forwardTypeUpdates` so that the type is resemed with original `n`.
1778-
let prevN = copyTree(n)
1779-
matches(c, n, prevN, m)
1780-
1781-
if m.state == csGotTyForward:
1782-
if prev == nil:
1783-
result = newTypeS(tyForward, c)
1784-
result.sym = s
1785-
else:
1786-
assignType(result, newTypeS(tyForward, c))
1787-
result.sym = s
1788-
c.forwardTypeUpdates.add (getCurrOwner(c), result, prevN) #fixes 1500
1789-
return
1777+
# that case, add `nOrig` to `c.forwardTypeUpdates` so that the type is resemed with original `n`.
1778+
let nOrig = copyTree(n)
1779+
matches(c, n, nOrig, m)
17901780

1791-
if m.state != csMatch:
1781+
if m.state notin {csMatch, csGotTyForward}:
17921782
var err = "cannot instantiate "
17931783
err.addTypeHeader(c.config, t)
17941784
err.add "\ngot: <$1>\nbut expected: <$2>" % [describeArgs(c, n), describeArgs(c, t.n, 0)]
@@ -1803,7 +1793,6 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
18031793
var isConcrete = true
18041794
let rType = m.call[0].typ
18051795
let mIndex = if rType != nil: rType.len - 1 else: -1
1806-
var hasForwardTypeParam = false
18071796
for i in 1..<m.call.len:
18081797
var typ = m.call[i].typ
18091798
# is this a 'typedesc' *parameter*? If so, use the typedesc type,
@@ -1820,15 +1809,12 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
18201809
skip = false
18211810
addToResult(typ, skip)
18221811

1823-
if typ.kind == tyForward:
1824-
hasForwardTypeParam = true
1825-
18261812
if isConcrete:
18271813
if s.ast == nil and s.typ.kind != tyCompositeTypeClass:
18281814
# XXX: What kind of error is this? is it still relevant?
18291815
localError(c.config, n.info, errCannotInstantiateX % s.name.s)
18301816
result = newOrPrevType(tyError, prev, c)
1831-
elif containsGenericInvocationWithForward(n[0]) or hasForwardTypeParam:
1817+
elif containsGenericInvocationWithForward(n[0]) or m.state == csGotTyForward:
18321818
# isConcrete == false means this generic type is not instanciated here because
18331819
# it invoked with generic parameters.
18341820
# Even if isConcrete == true, don't instanciate it now if there are
@@ -1852,7 +1838,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
18521838
else:
18531839
assignType(result, newTypeS(tyForward, c))
18541840
result.sym = s
1855-
c.forwardTypeUpdates.add (getCurrOwner(c), result, prevN) #fixes 1500
1841+
c.forwardTypeUpdates.add (getCurrOwner(c), result, nOrig) #fixes 1500
18561842
return
18571843
else:
18581844
result = instGenericContainer(c, n.info, result,
@@ -2307,10 +2293,10 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
23072293
elif op.s == "owned" and optOwnedRefs notin c.config.globalOptions and n.len == 2:
23082294
result = semTypeExpr(c, n[1], prev)
23092295
else:
2310-
let prevN = copyTree(n)
2296+
let nOrig = copyTree(n)
23112297
result = semTypeExpr(c, n, prev)
23122298
if result.kind == tyForward:
2313-
c.forwardTypeUpdates.add (getCurrOwner(c), result, prevN)
2299+
c.forwardTypeUpdates.add (getCurrOwner(c), result, nOrig)
23142300
of nkWhenStmt:
23152301
var whenResult = semWhen(c, n, false)
23162302
if whenResult.kind == nkStmtList: whenResult.transitionSonsKind(nkStmtListType)

0 commit comments

Comments
 (0)