Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-defined typeclasses or type aliases in generic procs cannot be distinct #24337

Open
mothfuzz opened this issue Oct 22, 2024 · 3 comments
Open

Comments

@mothfuzz
Copy link

Description

When defining a custom type alias or type class, the distinct keyword in argument position seems to not do anything as implied in the manual. It neither works with explicit nor implicit generics.

type Array2d[W, H: static[int]] = array[H, array[W, int]]

proc normal(a: Array2d, b: Array2d) =
  echo len(a), ", ", len(b)

proc dist(a: Array2d, b: distinct Array2d) =
  echo len(a), ", ", len(b)

proc doubleDist(a: distinct Array2d, b: distinct Array2d) =
  echo len(a), ", ", len(b)
  
proc explicit[A, B: distinct Array2d](a: A, b: B) =
  echo len(a), ", ", len(b)
  
let a = [[0, 1]]
let b = [[0, 1, 2]]
explicit(a, b)
doubleDist(a, b)
dist(a, b)
normal(a, b)

Nim Version

Nim Compiler Version 2.2.0 [Windows: amd64]
Compiled at 2024-10-02
Copyright (c) 2006-2024 by Andreas Rumpf

Current Output

Error: type mismatch
Expression: explicit(a, b)
  [1] a: array[0..0, array[0..1, int]]
  [2] b: array[0..0, array[0..2, int]]

Expected one of (first mismatch at [position]):
[1] proc explicit[A, B: distinct Array2d](a: A; b: B)

Expected Output

1, 1
1, 1
1, 1
1, 1

Known Workarounds

No response

Additional Information

No response

@ringabout
Copy link
Member

!nim c

type Array2d[W, H: static[int]] = array[H, array[W, int]]

proc normal(a: Array2d, b: Array2d) =
  echo len(a), ", ", len(b)

proc dist(a: Array2d, b: distinct Array2d) =
  echo len(a), ", ", len(b)

proc doubleDist(a: distinct Array2d, b: distinct Array2d) =
  echo len(a), ", ", len(b)
  
proc explicit[A, B: distinct Array2d](a: A, b: B) =
  echo len(a), ", ", len(b)
  
let a = [[0, 1]]
let b = [[0, 1, 2]]
explicit(a, b)
doubleDist(a, b)
dist(a, b)
normal(a, b)

Copy link
Contributor

🐧 Linux bisect by @ringabout (member)
devel 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-22T01:52:35
  • Finished 2024-10-22T01:52:35
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Array2d"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("W"),
          newIdentNode("H"),
          nnkBracketExpr.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("array"),
        newIdentNode("H"),
        nnkBracketExpr.newTree(
          newIdentNode("array"),
          newIdentNode("W"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("normal"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Array2d"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doubleDist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("explicit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("A"),
        newIdentNode("B"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("A"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("B"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1)
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("b"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1),
          newLit(2)
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("explicit"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("doubleDist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("dist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("normal"),
    newIdentNode("a"),
    newIdentNode("b")
  )
)
stable 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-22T01:52:39
  • Finished 2024-10-22T01:52:40
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Array2d"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("W"),
          newIdentNode("H"),
          nnkBracketExpr.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("array"),
        newIdentNode("H"),
        nnkBracketExpr.newTree(
          newIdentNode("array"),
          newIdentNode("W"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("normal"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Array2d"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doubleDist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("explicit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("A"),
        newIdentNode("B"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("A"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("B"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1)
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("b"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1),
          newLit(2)
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("explicit"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("doubleDist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("dist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("normal"),
    newIdentNode("a"),
    newIdentNode("b")
  )
)
2.0.10 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-22T01:52:43
  • Finished 2024-10-22T01:52:43
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Array2d"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("W"),
          newIdentNode("H"),
          nnkBracketExpr.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("array"),
        newIdentNode("H"),
        nnkBracketExpr.newTree(
          newIdentNode("array"),
          newIdentNode("W"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("normal"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Array2d"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doubleDist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("explicit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("A"),
        newIdentNode("B"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("A"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("B"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1)
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("b"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1),
          newLit(2)
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("explicit"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("doubleDist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("dist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("normal"),
    newIdentNode("a"),
    newIdentNode("b")
  )
)
2.0.0 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-22T01:52:47
  • Finished 2024-10-22T01:52:47
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Array2d"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("W"),
          newIdentNode("H"),
          nnkBracketExpr.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("array"),
        newIdentNode("H"),
        nnkBracketExpr.newTree(
          newIdentNode("array"),
          newIdentNode("W"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("normal"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Array2d"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doubleDist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("explicit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("A"),
        newIdentNode("B"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("A"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("B"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1)
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("b"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1),
          newLit(2)
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("explicit"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("doubleDist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("dist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("normal"),
    newIdentNode("a"),
    newIdentNode("b")
  )
)
1.6.20 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-22T01:52:50
  • Finished 2024-10-22T01:52:50
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Array2d"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("W"),
          newIdentNode("H"),
          nnkBracketExpr.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("array"),
        newIdentNode("H"),
        nnkBracketExpr.newTree(
          newIdentNode("array"),
          newIdentNode("W"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("normal"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Array2d"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doubleDist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("explicit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("A"),
        newIdentNode("B"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("A"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("B"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1)
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("b"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1),
          newLit(2)
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("explicit"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("doubleDist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("dist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("normal"),
    newIdentNode("a"),
    newIdentNode("b")
  )
)
1.4.8 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-22T01:52:54
  • Finished 2024-10-22T01:52:54
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Array2d"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("W"),
          newIdentNode("H"),
          nnkBracketExpr.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("array"),
        newIdentNode("H"),
        nnkBracketExpr.newTree(
          newIdentNode("array"),
          newIdentNode("W"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("normal"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Array2d"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doubleDist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("explicit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("A"),
        newIdentNode("B"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("A"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("B"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1)
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("b"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1),
          newLit(2)
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("explicit"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("doubleDist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("dist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("normal"),
    newIdentNode("a"),
    newIdentNode("b")
  )
)
1.2.18 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-22T01:52:57
  • Finished 2024-10-22T01:52:57
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Array2d"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("W"),
          newIdentNode("H"),
          nnkBracketExpr.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("array"),
        newIdentNode("H"),
        nnkBracketExpr.newTree(
          newIdentNode("array"),
          newIdentNode("W"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("normal"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Array2d"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doubleDist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("explicit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("A"),
        newIdentNode("B"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("A"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("B"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1)
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("b"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1),
          newLit(2)
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("explicit"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("doubleDist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("dist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("normal"),
    newIdentNode("a"),
    newIdentNode("b")
  )
)
1.0.10 👎 FAIL

Output


IR

Compiled filesize 0 (0 bytes)

Stats

  • Started 2024-10-22T01:53:00
  • Finished 2024-10-22T01:53:00
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Array2d"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("W"),
          newIdentNode("H"),
          nnkBracketExpr.newTree(
            newIdentNode("static"),
            newIdentNode("int")
          ),
          newEmptyNode()
        )
      ),
      nnkBracketExpr.newTree(
        newIdentNode("array"),
        newIdentNode("H"),
        nnkBracketExpr.newTree(
          newIdentNode("array"),
          newIdentNode("W"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("normal"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("Array2d"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("Array2d"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("doubleDist"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("explicit"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("A"),
        newIdentNode("B"),
        nnkDistinctTy.newTree(
          newIdentNode("Array2d")
        ),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("a"),
        newIdentNode("A"),
        newEmptyNode()
      ),
      nnkIdentDefs.newTree(
        newIdentNode("b"),
        newIdentNode("B"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCommand.newTree(
        newIdentNode("echo"),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("a")
        ),
        newLit(", "),
        nnkCall.newTree(
          newIdentNode("len"),
          newIdentNode("b")
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("a"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1)
        )
      )
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("b"),
      newEmptyNode(),
      nnkBracket.newTree(
        nnkBracket.newTree(
          newLit(0),
          newLit(1),
          newLit(2)
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("explicit"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("doubleDist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("dist"),
    newIdentNode("a"),
    newIdentNode("b")
  ),
  nnkCall.newTree(
    newIdentNode("normal"),
    newIdentNode("a"),
    newIdentNode("b")
  )
)
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.4
  • Created 2024-10-22T01:52:05Z
  • Comments 1
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 28 mins bisecting 8 commits at 0 commits per second

@metagn
Copy link
Collaborator

metagn commented Oct 22, 2024

static parameters in tyCompositeTypeClass keep the id of the original param, which universally matches that parameter to the first matching value.

IMO the solution is to add a type binding layer when matching tyCompositeTypeClass in sigmatch like in #24250, but #24250 needs a slight modification: only generic parameters belonging to the matched candidate should be matched in every previous binding layer, other generic parameters (like in this case, W and H) should only be matched in the current layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants