Skip to content

Commit

Permalink
fix CI, interesting setter change?
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Sep 17, 2023
1 parent fc78fd1 commit bf46963
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ proc semSymChoice(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: P
result = fitNode(c, expectedType, result, n.info)
if result.kind == nkSym:
result = semSym(c, result, result.sym, flags)
if isSymChoice(result) and {efAllowSymChoice, efDetermineType} * flags == {}:
if isSymChoice(result) and efAllowSymChoice notin flags:
# some contexts might want sym choices preserved for later disambiguation
# in general though they are ambiguous
let first = n[0].sym
Expand Down Expand Up @@ -1462,6 +1462,7 @@ proc builtinFieldAccess(c: PContext; n: PNode; flags: var TExprFlags): PNode =
onUse(n[1].info, s)
return

# extra flags since LHS may become a call operand:
n[0] = semExprWithType(c, n[0], flags+{efDetermineType, efWantIterable, efAllowSymChoice})
#restoreOldStyleType(n[0])
var i = considerQuotedIdent(c, n[1], n)
Expand Down Expand Up @@ -1716,7 +1717,7 @@ proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode =
# this is ugly. XXX Semantic checking should use the ``nfSem`` flag for
# nodes?
let aOrig = nOrig[0]
result = newTreeI(nkCall, n.info, setterId, a[0], semExprWithType(c, n[1]))
result = newTreeI(nkCall, n.info, setterId, a[0], n[1])
result.flags.incl nfDotSetter
let orig = newTreeI(nkCall, n.info, setterId, aOrig[0], nOrig[1])
result = semOverloadedCallAnalyseEffects(c, result, orig, {})
Expand Down
4 changes: 3 additions & 1 deletion compiler/seminst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
for i in 1..<def.len:
def[i] = replaceTypeVarsN(cl, def[i], 1)

def = semExprWithType(c, def)
# allow symchoice since node will be fit later
# although expectedType should cover it
def = semExprWithType(c, def, {efAllowSymChoice}, typeToFit)
if def.referencesAnotherParam(getCurrOwner(c)):
def.flags.incl nfDefaultRefsParam

Expand Down
2 changes: 1 addition & 1 deletion compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
def.typ = makeTypeFromExpr(c, def.copyTree)
break determineType

def = semExprWithType(c, def, {efDetermineType}, defTyp)
def = semExprWithType(c, def, {efDetermineType, efAllowSymChoice}, defTyp)
if def.referencesAnotherParam(getCurrOwner(c)):
def.flags.incl nfDefaultRefsParam

Expand Down
3 changes: 2 additions & 1 deletion tests/errmsgs/t8064.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ values


discard """
errormsg: "expression has no type: values"
# either this or "expression has no type":
errormsg: "ambiguous identifier 'values' -- use one of the following:"
"""
10 changes: 10 additions & 0 deletions tests/specialops/tsetter.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
block: # ensure RHS of setter statement is treated as call operand
proc `b=`(a: var int, c: proc (x: int): int) =
a = c(a)

proc foo(x: int): int = x + 1
proc foo(x: float): float = x - 1

var a = 123
a.b = foo
doAssert a == 124

0 comments on commit bf46963

Please sign in to comment.