diff options
-rw-r--r-- | compiler/semgnrc.nim | 10 | ||||
-rw-r--r-- | tests/generics/mdotlookup.nim | 3 | ||||
-rw-r--r-- | tests/generics/timports.nim | 6 |
3 files changed, 15 insertions, 4 deletions
diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 7dec8a30d..44f396996 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -138,7 +138,8 @@ proc newDot(n, b: PNode): PNode = result.add(b) proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags, - ctx: var GenericCtx; isMacro: var bool): PNode = + ctx: var GenericCtx; isMacro: var bool; + inCall = false): PNode = assert n.kind == nkDotExpr semIdeForTemplateOrGenericCheck(c.config, n, ctx.cursorInBody) @@ -152,8 +153,9 @@ proc fuzzyLookup(c: PContext, n: PNode, flags: TSemGenericFlags, result = n let n = n[1] let ident = considerQuotedIdent(c, n) - var candidates = searchInScopesFilterBy(c, ident, routineKinds+{skType}) - # skType here because could be type conversion + # could be type conversion if like a.T and not a.T() + let symKinds = if inCall: routineKinds else: routineKinds+{skType} + var candidates = searchInScopesFilterBy(c, ident, symKinds) if candidates.len > 0: let s = candidates[0] # XXX take into account the other candidates! isMacro = s.kind in {skTemplate, skMacro} @@ -281,7 +283,7 @@ proc semGenericStmt(c: PContext, n: PNode, onUse(fn.info, s) first = 1 elif fn.kind == nkDotExpr: - result[0] = fuzzyLookup(c, fn, flags, ctx, mixinContext) + result[0] = fuzzyLookup(c, fn, flags, ctx, mixinContext, inCall = true) first = 1 # Consider 'when declared(globalsSlot): ThreadVarSetValue(globalsSlot, ...)' # in threads.nim: the subtle preprocessing here binds 'globalsSlot' which diff --git a/tests/generics/mdotlookup.nim b/tests/generics/mdotlookup.nim index 215f75003..090b97771 100644 --- a/tests/generics/mdotlookup.nim +++ b/tests/generics/mdotlookup.nim @@ -23,3 +23,6 @@ proc doStrip*[T](a: T): string = type Foo = int32 proc baz2*[T](y: int): auto = result = y.Foo + +proc set*(x: var int, a, b: string) = + x = a.len + b.len diff --git a/tests/generics/timports.nim b/tests/generics/timports.nim index df830c1f0..43f096664 100644 --- a/tests/generics/timports.nim +++ b/tests/generics/timports.nim @@ -40,6 +40,12 @@ block tdotlookup: doAssert doStrip(123) == "123" # bug #14254 doAssert baz2[float](1'i8) == 1 + # bug #21883 + proc abc[T: not not int](x: T): T = + var x = x + x.set("hello", "world") + result = x + doAssert abc(5) == 10 block tmodule_same_as_proc: # bug #1965 |