From 42ff3aa75a3c352c2b6bcb2301538f25ee8006e8 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 14 Oct 2022 12:00:38 +0200 Subject: [PATCH] fixes #3748 (#20563) * fixes #3748 * fix the regression * don't use the new allocator for the SSL wrapper * fixes regression (cherry picked from commit 07b645342abd06b2323df042c170eb847f51880d) --- compiler/semdata.nim | 2 +- compiler/semexprs.nim | 7 ++++--- tests/overload/toverl4.nim | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/compiler/semdata.nim b/compiler/semdata.nim index 6f4670aafd..2b50fea13d 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -67,7 +67,7 @@ type efWantStmt, efAllowStmt, efDetermineType, efExplain, efWantValue, efOperand, efNoSemCheck, efNoEvaluateGeneric, efInCall, efFromHlo, efNoSem2Check, - efNoUndeclared + efNoUndeclared, efIsDotCall # Use this if undeclared identifiers should not raise an error during # overload resolution. diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 6827f933cb..b7037d8d1d 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -988,7 +988,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType var prc = n[0] if n[0].kind == nkDotExpr: checkSonsLen(n[0], 2, c.config) - let n0 = semFieldAccess(c, n[0]) + let n0 = semFieldAccess(c, n[0], {efIsDotCall}) if n0.kind == nkDotCall: # it is a static call! result = n0 @@ -1519,8 +1519,9 @@ proc dotTransformation(c: PContext, n: PNode): PNode = proc semFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode = # this is difficult, because the '.' is used in many different contexts # in Nim. We first allow types in the semantic checking. - result = builtinFieldAccess(c, n, flags) - if result == nil: + result = builtinFieldAccess(c, n, flags - {efIsDotCall}) + if result == nil or ((result.typ == nil or result.typ.skipTypes(abstractInst).kind != tyProc) and + efIsDotCall in flags and callOperator notin c.features): result = dotTransformation(c, n) proc buildOverloadedSubscripts(n: PNode, ident: PIdent): PNode = diff --git a/tests/overload/toverl4.nim b/tests/overload/toverl4.nim index 5379256747..455a735151 100644 --- a/tests/overload/toverl4.nim +++ b/tests/overload/toverl4.nim @@ -75,3 +75,17 @@ proc add*[TKey, TData](root: var PElement[TKey, TData], key: TKey, data: TData) var tree = PElement[int, int](kind: ElementKind.inner, key: 0, left: nil, right: nil) let result = add(tree, 1, 1) echo(result) + +# bug #3748 +type + Foo = object + bar: int + +proc bar(cur: Foo, val: int, s:seq[string]) = + discard cur.bar + +proc does_fail(): Foo = + let a = @["a"] + result.bar(5, a) + +doAssert does_fail().bar == 0