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

New styled concepts doesn't work with generic recursive types when T is specified explicitly #22839

Closed
saffage opened this issue Oct 18, 2023 · 1 comment · Fixed by #24244
Closed

Comments

@saffage
Copy link

saffage commented Oct 18, 2023

Description

The following example produces a compilation error.

type
  Comparable = concept
    proc `<`(a, b: Self): bool
  
  # Works with this.
  # Comparable = concept a
  #   `<`(a, a) is bool
  
  # Doesn't work with the new style concept.
  Node[T: Comparable] = object
    data: T
    next: ref Node[T]
    
  # Works without specifying a concept.
  # Node[T] = object
  #   data: T
  #   next: ref Node[T]

Nim Version

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

active boot switches: -d:release


Nim Compiler Version 2.0.0 [Windows: amd64]
Compiled at 2023-08-01
Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release


Nim Compiler Version 2.1.1 [Windows: amd64]
Compiled at 2023-10-17
Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release

Current Output

Error: cannot instantiate Node{None} [type declared in C:\Projects\TestNim\recursive_concept.nim(13, 3)]        
got: <typedesc[T: Comparable]>
but expected: <T: Comparable>

Expected Output

Successful compilation

Possible Solution

No response

Additional Information

No response

@metagn
Copy link
Collaborator

metagn commented Aug 24, 2024

Doesn't need to be recursive, just needs to match a constraint again:

type
  Comparable = concept
    proc `<`(a, b: Self): bool
  Foo[T: Comparable] = object
  Node[T: Comparable] = Foo[T]

The problem is the type Comparable doesn't match itself, it only checks for concrete types

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

Successfully merging a pull request may close this issue.

2 participants