Created
April 1, 2025 02:18
-
-
Save marcinczenko/cb48898d24314fbdebe57fd815c3c1be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{.push raises: [].} | |
import pkg/chronos | |
type | |
MyError = object of CatchableError | |
Handle1 = Future[void].Raising([CancelledError]) | |
Handle2 = Future[void].Raising([CancelledError, MyError]) | |
SomeType = object | |
name: string | |
handle1: Handle1 | |
handle2: Handle2 | |
proc `$`(t: SomeType): string = | |
t.name | |
# The key to understand the failures is by reading this from | |
# .nimble/pkgs2/chronos-4.0.4-455802a90204d8ad6b31d53f2efff8ebfe4c834a/chronos/internal/ | |
# raisesfutures.nim | |
# type | |
# InternalRaisesFuture*[T, E] = ref object of Future[T] | |
# ## Future with a tuple of possible exception types | |
# ## eg InternalRaisesFuture[void, (ValueError, OSError)] | |
# ## | |
# ## This type gets injected by `async: (raises: ...)` and similar utilities | |
# ## and should not be used manually as the internal exception representation | |
# ## is subject to change in future chronos versions. | |
# # TODO https://github.com/nim-lang/Nim/issues/23418 | |
# # TODO https://github.com/nim-lang/Nim/issues/23419 | |
# when E is void: | |
# dummy: E | |
# else: | |
# dummy: array[0, E] | |
let t = SomeType( | |
name: "example1", | |
# both fail | |
# type mismatch: got 'Future[system.void]' for ' | |
# newFutureImpl(srcLocImpl("", (filename: "raisingfutures.nim", line: 44, | |
# column: 26).filename, (filename: "raisingfutures.nim", line: 44, | |
# column: 26).line), {})' but expected 'Handle1 = InternalRaisesFuture[system.void, | |
# (CancelledError,)]' | |
# handle1: newFuture[void](), | |
# type mismatch: got 'Future[system.void]' for ' | |
# newFutureImpl(srcLocImpl("", (filename: "raisingfutures.nim", line: 50, | |
# column: 26).filename, (filename: "raisingfutures.nim", line: 50, | |
# column: 26).line), {})' but expected 'Handle2 = InternalRaisesFuture[system.void, | |
# (CancelledError, MyError)]' | |
# handle2: newFuture[void](), | |
) | |
proc getHandle1(): Future[void] {.async: (raw: true, raises: [CancelledError]).} = | |
## Add an event for a block | |
## | |
let t = SomeType( | |
name: "example2", | |
handle1: newFuture[void](), | |
# handle2 does not compile: | |
# type mismatch: got 'Handle1' for ' | |
# newInternalRaisesFutureImpl(srcLocImpl("", (filename: "raisingfutures.nim", | |
# line: 66, column: 28).filename, (filename: "raisingfutures.nim", | |
# line: 66, column: 28).line), {})' but expected | |
# 'Handle2 = InternalRaisesFuture[system.void, | |
# (CancelledError, MyError)]' | |
# handle2: newFuture[void](), | |
) | |
echo t | |
t.handle1 | |
proc getHandle2(): Future[void] {.async: (raw: true, raises: [CancelledError, MyError]).} = | |
## Add an event for a block | |
## | |
let t = SomeType( | |
name: "example3", | |
# handle1 does not compile: | |
# type mismatch: got 'Handle2' for ' | |
# newInternalRaisesFutureImpl(srcLocImpl("", (filename: "raisingfutures.nim", | |
# line: 85, column: 28).filename, (filename: "raisingfutures.nim", | |
# line: 85, column: 28).line), {})' but expected | |
# 'Handle1 = InternalRaisesFuture[system.void, (CancelledError,)]' | |
# handle1: newFuture[void](), | |
handle2: newFuture[void](), | |
) | |
echo t | |
t.handle2 | |
proc newSomeType(): SomeType = | |
## Add an event for a block | |
## | |
let t = SomeType( | |
name: "example4", | |
# both does not compile | |
# type mismatch: got 'Future[system.void]' for ' | |
# newFutureImpl(srcLocImpl("", (filename: "raisingfutures.nim", line: 104, | |
# column: 28). filename, (filename: "raising.nim", line: 104, column: 28).line), | |
# {})' but expected 'Handle1 = InternalRaisesFuture[system.void, | |
# (CancelledError,)]' | |
# handle1: newFuture[void](), | |
# type mismatch: got 'Future[system.void]' for ' | |
# newFutureImpl(srcLocImpl("", (filename: "raisingfutures.nim", line: 110, | |
# column: 28). filename, (filename: "raising.nim", line: 110, column: 28).line), | |
# {})' but expected 'Handle2 = InternalRaisesFuture[system.void, | |
# (CancelledError, MyError)]' | |
# handle2: newFuture[void](), | |
) | |
t | |
echo t | |
discard getHandle1() | |
discard getHandle2() | |
echo newSomeType() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment