summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/sigmatch.nim18
-rw-r--r--tests/overload/toverload_various.nim50
2 files changed, 59 insertions, 9 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 339af007a..19ceb61ca 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1480,6 +1480,15 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
       #InternalError("typeRel: tyGenericInvocation -> tyGenericInvocation")
       # simply no match for now:
       discard
+    elif x.kind == tyGenericInst and f.sons[0] == x.sons[0] and
+          sonsLen(x) - 1 == sonsLen(f):
+      for i in 1 ..< sonsLen(f):
+        if x.sons[i].kind == tyGenericParam:
+          internalError(c.c.graph.config, "wrong instantiated type!")
+        elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype:
+          # Workaround for regression #4589
+          if f.sons[i].kind != tyTypeDesc: return
+      result = isGeneric
     elif x.kind == tyGenericInst and isGenericSubType(c, x, f, depth, f) and
           (sonsLen(x) - 1 == sonsLen(f)):
       # do not recurse here in order to not K bind twice for this code:
@@ -1492,15 +1501,6 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
       # x.setColor()
       c.inheritancePenalty += depth
       result = isGeneric
-    elif x.kind == tyGenericInst and f.sons[0] == x.sons[0] and
-          sonsLen(x) - 1 == sonsLen(f):
-      for i in 1 ..< sonsLen(f):
-        if x.sons[i].kind == tyGenericParam:
-          internalError(c.c.graph.config, "wrong instantiated type!")
-        elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype:
-          # Workaround for regression #4589
-          if f.sons[i].kind != tyTypeDesc: return
-      result = isGeneric
     else:
       let genericBody = f.sons[0]
       var askip = skippedNone
diff --git a/tests/overload/toverload_various.nim b/tests/overload/toverload_various.nim
index 81564a7a9..78497e607 100644
--- a/tests/overload/toverload_various.nim
+++ b/tests/overload/toverload_various.nim
@@ -16,6 +16,7 @@ static: literal
 static: constant folding
 static: static string
 foo1
+1
 '''
 """
 
@@ -220,3 +221,52 @@ proc regr(p: Foo[void]): seq[int] =
 
 discard regr(Foo[int]())
 discard regr(Foo[void]())
+
+
+type
+  Sha2Context*[bits: static[int],
+               bsize: static[int],
+               T: uint32|uint64] = object
+    count: array[2, T]
+    state: array[8, T]
+    buffer: array[bsize, byte]
+
+  sha224* = Sha2Context[224, 64, uint32]
+  sha256* = Sha2Context[256, 64, uint32]
+  sha384* = Sha2Context[384, 128, uint64]
+  sha512* = Sha2Context[512, 128, uint64]
+  sha512_224* = Sha2Context[224, 128, uint64]
+  sha512_256* = Sha2Context[256, 128, uint64]
+
+type
+  RipemdContext*[bits: static[int]] = object
+    count: array[2, uint32]
+    state: array[bits div 32, uint32]
+    buffer: array[64, byte]
+
+  ripemd128* = RipemdContext[128]
+  ripemd160* = RipemdContext[160]
+  ripemd256* = RipemdContext[256]
+  ripemd320* = RipemdContext[320]
+
+const
+  MaxHmacBlockSize = 256
+
+type
+  HMAC*[HashType] = object
+    mdctx: HashType
+    opadctx: HashType
+
+template sizeBlock*(h: HMAC[Sha2Context]): uint = 1u
+template sizeBlock*(h: HMAC[RipemdContext]): uint = 0u
+
+proc init*[T](hmctx: HMAC[T], key: ptr byte, ulen: uint) =
+  const sizeBlock = hmctx.sizeBlock
+  echo sizeBlock
+
+proc hmac*[A, B](HashType: typedesc, key: openarray[A],
+                 data: openarray[B]) =
+  var ctx: HMAC[HashType]
+  ctx.init(nil, 0)
+
+sha256.hmac("", "")