Skip to content

Compilation error when using type-generic proc in type definition #20514

@rotu

Description

@rotu

What happened?

Using prod in a type definition causes the compiler to fail with an uninformative error message.

import std/math

type Foo[S:static[array[2, int]]] = object
  values: array[prod(S), float]

echo sizeof(Foo[[4,5]])

Curiously, replacing prod with sum causes a different outcome. The below program erroneously prints 1:

import std/math

type Foo[S:static[array[2, int]]] = object
  values: array[sum(S), float]

echo sizeof(Foo[[4,5]])

Nim Version

Nim Compiler Version 1.7.3 [Windows: amd64]
Compiled at 2022-10-07
Copyright (c) 2006-2022 by Andreas Rumpf

active boot switches: -d:release

Current Standard Output Logs

C:\Users\dan\.choosenim\toolchains\nim-#devel\lib\pure\math.nim(357, 3) Error: cannot generate VM code for result

Expected Standard Output Logs

No response

Possible Solution

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions