Skip to content

Compiler crash with sequence of proc #19562

@iacore

Description

@iacore

When I was trying to make mapIt shorter in #19557, I discovered this bug.

Example

template mapIt*(s: typed, op: untyped): untyped =
  type OutType = typeof(
    block:
      var it{.inject.}: typeof(items(s));
      op
  )

  block:
    var result: seq[OutType]
    for it {.inject.} in s:
      result &= op
    result

static:
  let m = @[func (x: int): int = x + 100, func (x: int): int = x + 200]
  echo m.mapIt(func (x: int): int = it(x)).mapIt(it 1)

Current Output

> nim r test2.nim
Hint: used config file '/home/user/.choosenim/toolchains/nim-1.6.4/config/nim.cfg' [Conf]
Hint: used config file '/home/user/.choosenim/toolchains/nim-1.6.4/config/config.nims' [Conf]
.........................................................fatal.nim(53)            sysFatal
Error: unhandled exception: index 9 not in 0 .. 3 [IndexDefect]

Expected Output

The compiler should not crash.

Additional Information

TODO: bisect
at least present since 1.7.1

> nim -v
Nim Compiler Version 1.6.4 [Linux: amd64]
Compiled at 2022-02-09
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 7994556f3804c217035c44b453a3feec64405758
active boot switches: -d:release

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