nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.57k stars 1.47k forks source link

Compiler error when passing a generic parameter restricted by some concept as a generic parameter to some type which restricts that parameter by the same concept. #24040

Open fabricio-p opened 2 months ago

fabricio-p commented 2 months ago

Description

type
  Xable = concept
    proc x(y: Self): int
  A[T: Xable] = tuple
    foo: T
  B*[T: Xable] = object
    a: A[T]

Nim Version

Nim Compiler Version 2.0.8 [Linux: amd64] Compiled at 2024-08-20 Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 5935c3bfa9fec6505394867b23510eb5cbab3dbf active boot switches: -d:release

Current Output

Hint: used config file '/home/fabricio/projects/third-party/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/fabricio/projects/third-party/Nim/config/config.nims' [Conf]
......................................................................
/home/fabricio/projects/nim/bug.nim(7, 9) Error: cannot instantiate A [type declared in /home/fabricio/projects/nim/bug.nim(4, 3)]
got: <typedesc[T: Xable]>
but expected: <T: Xable>

Expected Output

Hint: used config file '/home/fabricio/projects/third-party/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/fabricio/projects/third-party/Nim/config/config.nims' [Conf]
......................................................................
Hint:  [Link]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
27783 lines; 0.265s; 30.402MiB peakmem; proj: /home/fabricio/projects/nim/bug.nim; out: /home/fabricio/projects/nim/bug [SuccessX]

Known Workarounds

Remove the concept restriction from one of the generic type parameters.

Additional Information

No response

juancarlospaco commented 2 months ago

!nim c

type
  Xable = concept
    proc x(y: Self): int
  A[T: Xable] = tuple
    foo: T
  B*[T: Xable] = object
    a: A[T]
github-actions[bot] commented 2 months ago
:penguin: Linux bisect by @juancarlospaco (collaborator)
devel :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-09-01T16:11:24
  • Finished 2024-09-01T16:11:24
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Xable"), newEmptyNode(), nnkTypeClassTy.newTree( newEmptyNode(), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkProcDef.newTree( newIdentNode("x"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newIdentNode("int"), nnkIdentDefs.newTree( newIdentNode("y"), newIdentNode("Self"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), newEmptyNode() ) ) ) ), nnkTypeDef.newTree( newIdentNode("A"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkTupleTy.newTree( nnkIdentDefs.newTree( newIdentNode("foo"), newIdentNode("T"), newEmptyNode() ) ) ), nnkTypeDef.newTree( nnkPostfix.newTree( newIdentNode("*"), newIdentNode("B") ), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkObjectTy.newTree( newEmptyNode(), newEmptyNode(), nnkRecList.newTree( nnkIdentDefs.newTree( newIdentNode("a"), nnkBracketExpr.newTree( newIdentNode("A"), newIdentNode("T") ), newEmptyNode() ) ) ) ) ) ) ```
stable :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-09-01T16:11:27
  • Finished 2024-09-01T16:11:28
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Xable"), newEmptyNode(), nnkTypeClassTy.newTree( newEmptyNode(), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkProcDef.newTree( newIdentNode("x"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newIdentNode("int"), nnkIdentDefs.newTree( newIdentNode("y"), newIdentNode("Self"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), newEmptyNode() ) ) ) ), nnkTypeDef.newTree( newIdentNode("A"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkTupleTy.newTree( nnkIdentDefs.newTree( newIdentNode("foo"), newIdentNode("T"), newEmptyNode() ) ) ), nnkTypeDef.newTree( nnkPostfix.newTree( newIdentNode("*"), newIdentNode("B") ), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkObjectTy.newTree( newEmptyNode(), newEmptyNode(), nnkRecList.newTree( nnkIdentDefs.newTree( newIdentNode("a"), nnkBracketExpr.newTree( newIdentNode("A"), newIdentNode("T") ), newEmptyNode() ) ) ) ) ) ) ```
2.0.8 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-09-01T16:11:28
  • Finished 2024-09-01T16:11:28
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Xable"), newEmptyNode(), nnkTypeClassTy.newTree( newEmptyNode(), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkProcDef.newTree( newIdentNode("x"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newIdentNode("int"), nnkIdentDefs.newTree( newIdentNode("y"), newIdentNode("Self"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), newEmptyNode() ) ) ) ), nnkTypeDef.newTree( newIdentNode("A"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkTupleTy.newTree( nnkIdentDefs.newTree( newIdentNode("foo"), newIdentNode("T"), newEmptyNode() ) ) ), nnkTypeDef.newTree( nnkPostfix.newTree( newIdentNode("*"), newIdentNode("B") ), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkObjectTy.newTree( newEmptyNode(), newEmptyNode(), nnkRecList.newTree( nnkIdentDefs.newTree( newIdentNode("a"), nnkBracketExpr.newTree( newIdentNode("A"), newIdentNode("T") ), newEmptyNode() ) ) ) ) ) ) ```
2.0.0 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-09-01T16:11:31
  • Finished 2024-09-01T16:11:32
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Xable"), newEmptyNode(), nnkTypeClassTy.newTree( newEmptyNode(), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkProcDef.newTree( newIdentNode("x"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newIdentNode("int"), nnkIdentDefs.newTree( newIdentNode("y"), newIdentNode("Self"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), newEmptyNode() ) ) ) ), nnkTypeDef.newTree( newIdentNode("A"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkTupleTy.newTree( nnkIdentDefs.newTree( newIdentNode("foo"), newIdentNode("T"), newEmptyNode() ) ) ), nnkTypeDef.newTree( nnkPostfix.newTree( newIdentNode("*"), newIdentNode("B") ), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkObjectTy.newTree( newEmptyNode(), newEmptyNode(), nnkRecList.newTree( nnkIdentDefs.newTree( newIdentNode("a"), nnkBracketExpr.newTree( newIdentNode("A"), newIdentNode("T") ), newEmptyNode() ) ) ) ) ) ) ```
1.6.20 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-09-01T16:11:35
  • Finished 2024-09-01T16:11:35
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Xable"), newEmptyNode(), nnkTypeClassTy.newTree( newEmptyNode(), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkProcDef.newTree( newIdentNode("x"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newIdentNode("int"), nnkIdentDefs.newTree( newIdentNode("y"), newIdentNode("Self"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), newEmptyNode() ) ) ) ), nnkTypeDef.newTree( newIdentNode("A"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkTupleTy.newTree( nnkIdentDefs.newTree( newIdentNode("foo"), newIdentNode("T"), newEmptyNode() ) ) ), nnkTypeDef.newTree( nnkPostfix.newTree( newIdentNode("*"), newIdentNode("B") ), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("T"), newIdentNode("Xable"), newEmptyNode() ) ), nnkObjectTy.newTree( newEmptyNode(), newEmptyNode(), nnkRecList.newTree( nnkIdentDefs.newTree( newIdentNode("a"), nnkBracketExpr.newTree( newIdentNode("A"), newIdentNode("T") ), newEmptyNode() ) ) ) ) ) ) ```
1.4.8 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-09-01T16:11:37
  • Finished 2024-09-01T16:11:37
  • Duration

AST

```nim ```
1.2.18 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-09-01T16:11:40
  • Finished 2024-09-01T16:11:40
  • Duration

AST

```nim ```
1.0.10 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-09-01T16:11:42
  • Finished 2024-09-01T16:11:42
  • Duration

AST

```nim ```
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.4
  • Created 2024-09-01T16:11:01Z
  • 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

:robot: Bug found in 21 mins bisecting 8 commits at 0 commits per second