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

Object types as generic constraints are treated as uninstantiated when passing subtypes #24447

Open
metagn opened this issue Nov 17, 2024 · 0 comments

Comments

@metagn
Copy link
Collaborator

metagn commented Nov 17, 2024

Originally mentioned in this comment: #7713 (comment)

Encountered in:

type
  Foo = object of RootObj
  Bar = object of Foo
  Baz[T:Foo] = object of RootObj
    val:T
let x = Baz[Bar]()#Error object constructor needs an object type
type
  Qux = object
    val:Baz[Bar]
let y = Qux() #Error: invalid type: 'Baz[Baz.T]' in this context: 'Qux' for let

concepts work:

type
  Foo = object of RootObj
  IsFoo = concept type t
    t is Foo
  Bar = object of Foo
  Baz[T:IsFoo] = object of RootObj
    val:T
  Qux = object
    val:Baz[Bar]
let x = Baz[Bar]()#fine
let y = Qux() #fine

another workaround:

func init[T:Foo](b: type Baz; c: typedesc[T]):Baz[T] = discard
let x = Baz.init(Bar)

Works if passing just Foo instead of Bar

@metagn metagn changed the title Object types as generic constraints do not work Object types as generic constraints do not work when passing subtypes Nov 17, 2024
@metagn metagn changed the title Object types as generic constraints do not work when passing subtypes Object types as generic constraints are treated as uninstantiated when passing subtypes Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant