Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace old problematic isNamedTuple implementation by TypeTrait isNamedTuple in dollars.nim #13347

Merged
merged 2 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions lib/system/dollars.nim
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ proc `$`*(t: typedesc): string {.magic: "TypeTrait".}
## doAssert $(type("Foo")) == "string"
## static: doAssert $(type(@['A', 'B'])) == "seq[char]"

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 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
Expand Down