diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 9a762d585b6f8..344f6fd5aeb50 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 57770c48669e0..664f1c30d55aa 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