-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
What happened?
Related issue that fixes a more fundamental version of this problem: #20681
This is basically a more specialized version/an edgecase of that very same issue, so I'll copy the initial description:
It is currently impossible to instantiate a distinct DateTime object at compile time. That makes it difficult to make use of nim 2's new feature of #20480 for any object with fields of a custom version of the DateTime type.
My original minimal example:
import std/times
type DjangoDateTime = distinct DateTime
type Default = object
data: DjangoDateTime = DjangoDateTime(DateTime())
let x = default(Default)
echo x.repr@ringabout narrowed down the issue more specifically to be
import std/times
import std/macros
type DjangoDateTime = distinct DateTime
block:
macro foo(x: static DjangoDateTime) =
discard x
macro foo2: untyped =
var x: DjangoDateTime = DjangoDateTime(DateTime())
result = quote do:
foo(`x`)
foo2()Nim Version
Nim Compiler Version 1.7.3 [Linux: amd64]
Compiled at 2022-10-29
Copyright (c) 2006-2022 by Andreas Rumpf
git hash: 534c97e
active boot switches: -d:release
However, I've been told by @ringabout that the issue in his example is more fundamental and replicable in older nim versions as well
Current Standard Output Logs
Attempt 1:
type mismatch: got 'DateTime' for 'DateTime(nanosecond: 0, second: 0, minute: 0, hour: 0, monthdayZero: 0,
monthZero: 0, year: 0, weekday: dMon, yearday: 0, isDst: false,
timezone: nil, utcOffset: 0)' but expected 'DjangoDateTime = distinct DateTime'
Attempt 2:
<PROJECT_PATH>/src/playground.nim(16, 7) template/generic instantiation of `foo2` from here
<PROJECT_PATH>/src/playground.nim(13, 14) Error: the field 'nanosecond' is not accessible.Expected Standard Output Logs
No compiler errorPossible Solution
This problem is absolutely beyond me, no idea.
Additional Information
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status