Skip to content

Generic enum parameter with array causes internal error #12263

@Clyybber

Description

@Clyybber

Example

import rationals

type
  Tile[n: enum] = array[n, int]
  Map[w, h: static int, n: enum] = array[w, array[h, Tile[n]]]
  TileId = int
  Coord = tuple[x, y: int]
  Rule[n: enum] = tuple[c: Coord, t: Tile[n]]
  Discriminator[n: enum] = seq[Rule[n]]
  Tileset[n: enum] = array[n, Discriminator[n]]

type Tiles = enum
  Air, Land, Water, Wall

let tileset: Tileset[Tiles] = [
  Air: @[
    ( (0, 0) , [Air: 1, Land: 0, Water: 0, Wall: 0].Tile ),
    ( (-1, 0) , [Air: 1, Land: 1, Water: 1, Wall: 0].Tile ),
  ],
  Land: @[
    ( (0, 0) , [Air: 0, Land: 1, Water: 0, Wall: 0].Tile ),
    ( (-1, 0) , [Air: 1, Land: 1, Water: 1, Wall: 0].Tile ),
  ],
  Water: @[
    ( (0, 0) , [Air: 0, Land: 0, Water: 1, Wall: 0].Tile ),
    ( (-1, 0) , [Air: 1, Land: 1, Water: 1, Wall: 0].Tile ),
  ],
  Wall: @[
    ( (0, 0) , [Air: 0, Land: 0, Water: 0, Wall: 1].Tile ),
    ( (1, 0) , [Air: 0, Land: 0, Water: 0, Wall: 1].Tile ),
  ],
]

Current Output

Error: internal error: invalid kind for lastOrd(tyAnything)
Traceback (most recent call last)
/home/clyybber/builds/nim/compiler/nim.nim(106) nim
/home/clyybber/builds/nim/compiler/nim.nim(83) handleCmdLine
/home/clyybber/builds/nim/compiler/cmdlinehelper.nim(98) loadConfigsAndRunMainCommand
/home/clyybber/builds/nim/compiler/main.nim(188) mainCommand
/home/clyybber/builds/nim/compiler/main.nim(92) commandCompileToC
/home/clyybber/builds/nim/compiler/modules.nim(144) compileProject
/home/clyybber/builds/nim/compiler/modules.nim(85) compileModule
/home/clyybber/builds/nim/compiler/passes.nim(210) processModule
/home/clyybber/builds/nim/compiler/passes.nim(86) processTopLevelStmt
/home/clyybber/builds/nim/compiler/sem.nim(601) myProcess
/home/clyybber/builds/nim/compiler/sem.nim(569) semStmtAndGenerateGenerics
/home/clyybber/builds/nim/compiler/semstmts.nim(2224) semStmt
/home/clyybber/builds/nim/compiler/semexprs.nim(987) semExprNoType
/home/clyybber/builds/nim/compiler/semexprs.nim(2742) semExpr
/home/clyybber/builds/nim/compiler/semstmts.nim(2164) semStmtList
/home/clyybber/builds/nim/compiler/semexprs.nim(2745) semExpr
/home/clyybber/builds/nim/compiler/semstmts.nim(454) semVarOrLet
/home/clyybber/builds/nim/compiler/semexprs.nim(64) semExprWithType
/home/clyybber/builds/nim/compiler/semexprs.nim(2707) semExpr
/home/clyybber/builds/nim/compiler/semexprs.nim(558) semArrayConstr
/home/clyybber/builds/nim/compiler/semexprs.nim(64) semExprWithType
/home/clyybber/builds/nim/compiler/semexprs.nim(2652) semExpr
/home/clyybber/builds/nim/compiler/semexprs.nim(968) semDirectOp
/home/clyybber/builds/nim/compiler/semexprs.nim(817) semOverloadedCallAnalyseEffects
/home/clyybber/builds/nim/compiler/semcall.nim(533) semOverloadedCall
/home/clyybber/builds/nim/compiler/semcall.nim(335) resolveOverloads
/home/clyybber/builds/nim/compiler/semcall.nim(93) pickBestCandidate
/home/clyybber/builds/nim/compiler/sigmatch.nim(2522) matches
/home/clyybber/builds/nim/compiler/sigmatch.nim(2459) matchesAux
/home/clyybber/builds/nim/compiler/sigmatch.nim(2261) prepareOperand
/home/clyybber/builds/nim/compiler/semexprs.nim(49) semOperand
/home/clyybber/builds/nim/compiler/semexprs.nim(2707) semExpr
/home/clyybber/builds/nim/compiler/semexprs.nim(558) semArrayConstr
/home/clyybber/builds/nim/compiler/semexprs.nim(64) semExprWithType
/home/clyybber/builds/nim/compiler/semexprs.nim(2703) semExpr
/home/clyybber/builds/nim/compiler/semexprs.nim(2515) semTupleConstr
/home/clyybber/builds/nim/compiler/semexprs.nim(2437) semTuplePositionsConstr
/home/clyybber/builds/nim/compiler/semexprs.nim(64) semExprWithType
/home/clyybber/builds/nim/compiler/semexprs.nim(2679) semExpr
/home/clyybber/builds/nim/compiler/semexprs.nim(1524) semArrayAccess
/home/clyybber/builds/nim/compiler/semexprs.nim(1435) semSubscript
/home/clyybber/builds/nim/compiler/semexprs.nim(64) semExprWithType
/home/clyybber/builds/nim/compiler/semexprs.nim(2614) semExpr
/home/clyybber/builds/nim/compiler/semexprs.nim(2644) semExpr
/home/clyybber/builds/nim/compiler/semexprs.nim(272) semConv
/home/clyybber/builds/nim/compiler/semcall.nim(446) inferWithMetatype
/home/clyybber/builds/nim/compiler/sigmatch.nim(2170) paramTypesMatch
/home/clyybber/builds/nim/compiler/sigmatch.nim(2014) paramTypesMatchAux
/home/clyybber/builds/nim/compiler/sigmatch.nim(1653) typeRel
/home/clyybber/builds/nim/compiler/sigmatch.nim(1209) typeRel
/home/clyybber/builds/nim/compiler/types.nim(823) lengthOrd
/home/clyybber/builds/nim/compiler/types.nim(781) lastOrd
/home/clyybber/builds/nim/compiler/msgs.nim(565) internalError
/home/clyybber/builds/nim/compiler/msgs.nim(443) rawMessage
/home/clyybber/builds/nim/compiler/msgs.nim(440) rawMessage
/home/clyybber/builds/nim/compiler/msgs.nim(356) handleError
/home/clyybber/builds/nim/compiler/msgs.nim(346) quit

Expected Output

Should compile

Additional Information

$ nim -v
Nim Compiler Version 1.0.0

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