Arraymancer icon indicating copy to clipboard operation
Arraymancer copied to clipboard

Importing std/enumerate breaks arraymancer

Open dain-xyz opened this issue 2 years ago • 1 comments

This works:

import arraymancer
let foo = @[1, 2, 3].to_tensor
echo foo

This doesn't:

import arraymancer
import std/enumerate

let foo = @[1, 2, 3].to_tensor
echo foo
Error: type mismatch: got <Tensor[system.int]>
but expected one of:
proc echo(x: varargs[typed, `$`])
  first type mismatch at position: 1
  required type for x: varargs[typed]
  but expression 'foo' is of type: Tensor[system.int]

expression: echo foo

Version info:

nim --version
Nim Compiler Version 1.6.0 [Linux: amd64]
Compiled at 2021-10-19
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 727c6378d2464090564dbcd9bc8b9ac648467e38
active boot switches: -d:release

dain-xyz avatar Dec 03 '21 11:12 dain-xyz

Interesting. Thanks for the report.

I stumbled on possibly the same issue before, but always in complex situations and could never find a simple example. I'll see whether I can fix it somehow.

edit:

The following is already enough to trigger the issue:

import arraymancer
import macros

macro enumerate*(x: ForLoopStmt): untyped =
  result.add newLit(0)

let foo = @[1, 2, 3].toTensor
echo foo

Note: The ForLoopStmt is required. If using typed or untyped it works. It also works if the argument of enumerate is not an add stmt (i.e. just discard or result = newStmtList(). Maybe something else triggers it too though).

Also changing the name of the macro to something other than enumerate makes the code compile. The issue is likely that the ForLoopStmt macros mess up the overload resolution within arraymancer, as there are enumerate iterators.

Vindaar avatar Dec 03 '21 12:12 Vindaar