Skip to content

Type tyAnything can't be matched to proc argument of typedesc type #13193

Closed
@mratsim

Description

@mratsim

Building on #13095 and its fix #13181, supportsCopyMem in a type section doesn't work with implicit generic parameters.
The error message in particular mentions type any which makes it hard to debug as there is no type any in the codebase.

Test case

import typetraits

type
  CpuStorage[T] {.shallow.} = ref object
    when supportsCopyMem(T):
      raw_buffer*: ptr UncheckedArray[T] # 8 bytes
      memalloc*: pointer                 # 8 bytes
      isMemOwner*: bool                  # 1 byte
    else: # Tensors of strings, other ref types or non-trivial destructors
      raw_buffer*: seq[T]                # 8 bytes (16 for seq v2 backed by destructors?)

  Tensor*[T] = object
    storage*: CpuStorage[T]

proc foo(t: Tensor): bool =
  # This breaks
  return false

proc bar[T](t: Tensor[T]): bool =
  return false

Error

Error: type mismatch: got <type any>
but expected one of: 
proc supportsCopyMem(t: typedesc): bool
  first type mismatch at position: 1
  required type for t: type T
  but expression 'T' is of type: type any

expression: supportsCopyMem(T)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions