mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-26 17:24:02 +00:00
fixes #22305 It seems that the generic type is cached somehow so that no hooks are instantiated for the generic type. There are only hooks for the instantiated type. When `lambdalifting` tries to create type bounds for the generic type, it cannot either find the instantiated hooks or instantiate the generic hooks since it lacks `SemContext`. It can use hooks for the instantiated type in this case
This commit is contained in:
57
tests/generics/t22305.nim
Normal file
57
tests/generics/t22305.nim
Normal file
@@ -0,0 +1,57 @@
|
||||
discard """
|
||||
joinable: false
|
||||
"""
|
||||
|
||||
import asyncdispatch, options
|
||||
|
||||
proc recv*[T](tc: ptr Channel[T]): Future[T] {.async.} =
|
||||
discard
|
||||
|
||||
type SharedBuf = object
|
||||
|
||||
type WorkProc[A, B] = proc(a: A): Option[B] {.nimcall.}
|
||||
|
||||
proc worker[TArg](p: TArg) {.thread, nimcall.} =
|
||||
discard
|
||||
|
||||
proc readFilesThread() =
|
||||
type TArg[A, B] =
|
||||
tuple[r: ptr Channel[Option[A]], w: ptr Channel[Option[B]], p: WorkProc[A, B]]
|
||||
|
||||
var readThread: Thread[TArg[int, SharedBuf]]
|
||||
|
||||
proc readFilesAd() {.async.} =
|
||||
var readChan: Channel[Option[int]]
|
||||
|
||||
type TArg[A, B] =
|
||||
tuple[r: ptr Channel[Option[A]], w: ptr Channel[Option[B]], p: WorkProc[A, B]]
|
||||
|
||||
var readThread: Thread[TArg[int, SharedBuf]]
|
||||
let test = await (addr readChan).recv()
|
||||
|
||||
joinThread(readThread)
|
||||
|
||||
waitFor readFilesAd()
|
||||
|
||||
type
|
||||
SharedPtr[T] = object
|
||||
p: ptr T
|
||||
|
||||
proc `=destroy`[T](self: var SharedPtr[T]) =
|
||||
discard
|
||||
|
||||
type
|
||||
SomethingObj[T] = object
|
||||
Something[T] = SharedPtr[SomethingObj[T]]
|
||||
|
||||
proc useSomething() =
|
||||
# discard Something[int]() # When you uncomment this line, it will compile successfully.
|
||||
discard Something[float]()
|
||||
|
||||
proc fn() =
|
||||
let thing = Something[int]()
|
||||
proc closure() =
|
||||
discard thing
|
||||
closure()
|
||||
|
||||
fn()
|
||||
Reference in New Issue
Block a user