summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2022-10-14 12:00:38 +0200
committerGitHub <noreply@github.com>2022-10-14 12:00:38 +0200
commit07b645342abd06b2323df042c170eb847f51880d (patch)
tree2645d5edd83defbdb46474de8bf8d9619132bba0
parentb793ca739448ba35b59c43b85706f1d202b31788 (diff)
downloadNim-07b645342abd06b2323df042c170eb847f51880d.tar.gz
fixes #3748 (#20563)
* fixes #3748

* fix the regression

* don't use the new allocator for the SSL wrapper

* fixes regression
-rw-r--r--compiler/semdata.nim2
-rw-r--r--compiler/semexprs.nim7
-rw-r--r--lib/wrappers/openssl.nim7
-rw-r--r--tests/overload/toverl4.nim14
4 files changed, 24 insertions, 6 deletions
diff --git a/compiler/semdata.nim b/compiler/semdata.nim
index 363b7e5a4..e9804fd56 100644
--- a/compiler/semdata.nim
+++ b/compiler/semdata.nim
@@ -69,7 +69,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 8c574e318..9cbe11616 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -973,7 +973,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
@@ -1474,8 +1474,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/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim
index 70fed664e..e9c9c581f 100644
--- a/lib/wrappers/openssl.nim
+++ b/lib/wrappers/openssl.nim
@@ -531,7 +531,10 @@ proc i2d_X509*(cert: PX509): string =
   if length.int <= 0:
     raise newException(Exception, "X.509 certificate encoding failed")
 
-when not useWinVersion and not defined(macosx) and not defined(android) and not defined(nimNoAllocForSSL):
+const
+  useNimsAlloc = not defined(nimNoAllocForSSL) and not defined(gcDestructors)
+
+when not useWinVersion and not defined(macosx) and not defined(android) and useNimsAlloc:
   proc CRYPTO_set_mem_functions(a,b,c: pointer){.cdecl,
     dynlib: DLLUtilName, importc.}
 
@@ -545,7 +548,7 @@ when not useWinVersion and not defined(macosx) and not defined(android) and not
     if p != nil: deallocShared(p)
 
 proc CRYPTO_malloc_init*() =
-  when not useWinVersion and not defined(macosx) and not defined(android) and not defined(nimNoAllocForSSL):
+  when not useWinVersion and not defined(macosx) and not defined(android) and useNimsAlloc:
     CRYPTO_set_mem_functions(allocWrapper, reallocWrapper, deallocWrapper)
 
 proc SSL_CTX_ctrl*(ctx: SslCtx, cmd: cint, larg: clong, parg: pointer): clong{.
diff --git a/tests/overload/toverl4.nim b/tests/overload/toverl4.nim
index 537925674..455a73515 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