Skip to content

Commit

Permalink
fix semFinishOperand for bracket expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed May 4, 2024
1 parent 1ef4d04 commit b01b361
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
15 changes: 8 additions & 7 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1021,10 +1021,14 @@ proc finishOperand(c: PContext, a: PNode): PNode =
localError(c.config, a.info, err)
considerGenSyms(c, result)

proc semFinishOperands(c: PContext; n: PNode) =
proc semFinishOperands(c: PContext; n: PNode; isBracketExpr = false) =
# this needs to be called to ensure that after overloading resolution every
# argument has been sem'checked:
for i in 1..<n.len:
# argument has been sem'checked

# skip the first argument for operands of `[]` since it may be an unresolved
# generic proc, which is handled in semMagic
let start = 1 + ord(isBracketExpr)
for i in start..<n.len:
n[i] = finishOperand(c, n[i])

proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags; expectedType: PType = nil): PNode =
Expand All @@ -1047,10 +1051,7 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags; expectedTy
of skMacro: result = semMacroExpr(c, result, orig, callee, flags, expectedType)
of skTemplate: result = semTemplateExpr(c, result, callee, flags, expectedType)
else:
if callee.magic notin {mArrGet, mArrPut, mNBindSym}:
# calls to `[]` can be explicit generic instantiations,
# don't sem every operand now, leave it to semmagic
semFinishOperands(c, result)
semFinishOperands(c, result, isBracketExpr = callee.magic in {mArrGet, mArrPut})
activate(c, result)
fixAbstractType(c, result)
analyseIfAddressTakenInCall(c, result)
Expand Down
24 changes: 24 additions & 0 deletions tests/generics/tnestedissues.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
block: # issue #23568
type G[T] = object
j: T
proc s[T](u: int) = discard
proc s[T]() = discard
proc c(e: int | int): G[G[G[int]]] = s[G[G[int]]]()
discard c(0)

import std/options

block: # issue #23310
type
BID = string or uint64
Future[T] = ref object of RootObj
internalValue: T
InternalRaisesFuture[T] = ref object of Future[T]
proc newInternalRaisesFutureImpl[T](): InternalRaisesFuture[T] =
let fut = InternalRaisesFuture[T]()
template newFuture[T](): auto =
newInternalRaisesFutureImpl[T]()
proc problematic(blockId: BID): Future[Option[seq[int]]] =
let resultFuture = newFuture[Option[seq[int]]]()
return resultFuture
let x = problematic("latest")

0 comments on commit b01b361

Please sign in to comment.