Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Nov 26, 2022
1 parent 3fbdb10 commit a76eeb4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ proc getMsgDiagnostic(c: PContext, flags: TExprFlags, n, f: PNode): string =
sym = nextOverloadIter(o, c, f)

let ident = considerQuotedIdent(c, f, n).s
if {nfDotField, nfDotSetter, nfExplicitCall} * n.flags <= {nfDotField, nfDotSetter}:
if nfExplicitCall notin n.flags and {nfDotField, nfDotSetter} * n.flags != {}:
let sym = n[1].typ.typSym
var typeHint = ""
if sym == nil:
Expand Down
8 changes: 5 additions & 3 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ proc overloadedCallOpr(c: PContext, n: PNode): PNode =
result = newNodeI(nkCall, n.info)
result.add newIdentNode(par, n.info)
for i in 0..<n.len: result.add n[i]
result = semExpr(c, result)
result = semExpr(c, result, flags = {efNoUndeclared})

proc changeType(c: PContext; n: PNode, newType: PType, check: bool) =
case n.kind
Expand Down Expand Up @@ -988,6 +988,8 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
let t = n[0].typ
if t != nil and t.kind in {tyVar, tyLent}:
n[0] = newDeref(n[0])
elif isSymChoice(n[0]):
return semDirectOp(c, n, flags, expectedType)
elif n[0].kind == nkBracketExpr:
let s = bracketedMacro(n[0])
if s != nil:
Expand Down Expand Up @@ -1042,10 +1044,10 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
instGenericConvertersSons(c, result, m)

else:
result = overloadedCallOpr(c, n)
result = overloadedCallOpr(c, n) # this uses efNoUndeclared
# Now that nkSym does not imply an iteration over the proc/iterator space,
# the old ``prc`` (which is likely an nkIdent) has to be restored:
if result == nil:
if result == nil or result.kind == nkEmpty:
# XXX: hmm, what kind of symbols will end up here?
# do we really need to try the overload resolution?
n[0] = prc
Expand Down
9 changes: 8 additions & 1 deletion tests/specialops/terrmsgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ block:

# non-routine type shows `()` overloads:
b(123) #[tt.Error
^ type mismatch: got <Bar, int literal(123)>]#
^ attempting to call routine: 'b']#

# issue #7777

Expand All @@ -74,3 +74,10 @@ block:

var tt: TestType
discard tt.field

block: # related to issue #6981
proc `()`(a:string, b:string):string = a & b
proc mewSeq[T](a,b:int)=discard
proc mewSeq[T](c:int)= discard
mewSeq[int]() #[tt.Error
^ type mismatch: got <>]#
22 changes: 22 additions & 0 deletions tests/specialops/tnewseq.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# issue #6981

import std/assertions

{.experimental: "callOperator".}

block: # issue #6981
proc `()`(a:string, b:string):string = a & b

var s = newSeq[int](3)

doAssert s == @[0, 0, 0]

block: # generalized example from #6981
proc mewSeq[T](a: int)=discard
proc mewSeq[T]()= discard
mewSeq[int]()

block: # issue #9831
type Foo = object
proc `()`(foo: Foo) = discard
let x = newSeq[int]()

0 comments on commit a76eeb4

Please sign in to comment.