From e4ad0ae5c41fa847797fb4d25bcabff3cdcb8966 Mon Sep 17 00:00:00 2001 From: Clyybber Date: Tue, 2 Feb 2021 21:43:02 +0100 Subject: [PATCH] Add testcase for #16897 (#16917) --- tests/concepts/tconcepts_issues.nim | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/concepts/tconcepts_issues.nim b/tests/concepts/tconcepts_issues.nim index 65f6d46604..ec7612b341 100644 --- a/tests/concepts/tconcepts_issues.nim +++ b/tests/concepts/tconcepts_issues.nim @@ -467,3 +467,36 @@ block misc_issues: # anyway and will be an error soon. var a: Cat = Cat() a.sayHello() + + +# bug #16897 + +type + Fp[N: static int, T] = object + big: array[N, T] + +type + QuadraticExt* = concept x + ## Quadratic Extension concept (like complex) + type BaseField = auto + x.c0 is BaseField + x.c1 is BaseField +var address = pointer(nil) +proc prod(r: var QuadraticExt, b: QuadraticExt) = + if address == nil: + address = unsafeAddr b + prod(r, b) + else: + assert address == unsafeAddr b + +type + Fp2[N: static int, T] {.byref.} = object + c0, c1: Fp[N, T] + +# This should be passed by reference, +# but concepts do not respect the 24 bytes rule +# or `byref` pragma. +var r, b: Fp2[6, uint64] + +prod(r, b) +