From 3b3b116e3384b11e42df648c6d60aa9b9f243f44 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 6 Feb 2020 18:13:04 -0800 Subject: [PATCH 1/2] replace old problematic isNamedTuple implementation by TypeTrait isNamedTuple --- lib/system/dollars.nim | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/lib/system/dollars.nim b/lib/system/dollars.nim index 64860ef399d1..57770c48669e 100644 --- a/lib/system/dollars.nim +++ b/lib/system/dollars.nim @@ -49,18 +49,7 @@ proc `$`*(t: typedesc): string {.magic: "TypeTrait".} ## doAssert $(type("Foo")) == "string" ## static: doAssert $(type(@['A', 'B'])) == "seq[char]" - -proc isNamedTuple(T: typedesc): bool = - # Taken from typetraits. - when T isnot tuple: result = false - else: - var t: T - for name, _ in t.fieldPairs: - when name == "Field0": - return compiles(t.Field0) - else: - return true - return false +proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".} proc `$`*[T: tuple|object](x: T): string = ## Generic ``$`` operator for tuples that is lifted from the components From 78e94f0f915a7db6b7c5050a7524a758fc3d9d5d Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 6 Feb 2020 18:29:34 -0800 Subject: [PATCH 2/2] fix for bootstrap --- compiler/condsyms.nim | 1 + lib/system/dollars.nim | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 9a762d585b6f..344f6fd5aeb5 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -103,6 +103,7 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimNewShiftOps") defineSymbol("nimHasCursor") defineSymbol("nimHasExceptionsQuery") + defineSymbol("nimHasIsNamedTuple") when defined(nimHasLibFFI): # Renaming as we can't conflate input vs output define flags; e.g. this diff --git a/lib/system/dollars.nim b/lib/system/dollars.nim index 57770c48669e..664f1c30d55a 100644 --- a/lib/system/dollars.nim +++ b/lib/system/dollars.nim @@ -49,7 +49,22 @@ proc `$`*(t: typedesc): string {.magic: "TypeTrait".} ## doAssert $(type("Foo")) == "string" ## static: doAssert $(type(@['A', 'B'])) == "seq[char]" -proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".} +when defined(nimHasIsNamedTuple): + proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".} +else: + # for bootstrap; remove after release 1.2 + proc isNamedTuple(T: typedesc): bool = + # Taken from typetraits. + when T isnot tuple: result = false + else: + var t: T + for name, _ in t.fieldPairs: + when name == "Field0": + return compiles(t.Field0) + else: + return true + return false + proc `$`*[T: tuple|object](x: T): string = ## Generic ``$`` operator for tuples that is lifted from the components