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

inheritance for generics does not work #88

Closed
Araq opened this issue Jan 11, 2012 · 9 comments

Comments

Projects
None yet
6 participants
@Araq
Copy link
Member

commented Jan 11, 2012

The following program should compile, but does not:


type
  TGen[T] = object
    field: T

  TDerived[T] = object of TGen[T]
    nextField: T

proc doSomething[T](x: ref TGen[T]) =
  type
    Ty = ref TDerived[T]
  echo Ty(x).nextField

var
  x: ref TDerived[string]
new(x)
x.nextField = "test"

doSomething(x)
@reactormonk

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2013

New code:

type
  TGen[T] = object {.inheritable.}
    field: T

  TDerived[T] = object of TGen[T]
    nextField: T

proc doSomething[T](x: ref TGen[T]) =
  type
    Ty = ref TDerived[T]
  echo Ty(x).nextField

var
  x: ref TDerived[string]
new(x)
x.nextField = "test"

doSomething(x)

Fails with:

test.nim(18, 12) Error: type mismatch: got (ref TDerived[string])
but expected one of: 
test.doSomething(x: ref TGen[T])
@ozra

This comment has been minimized.

Copy link
Contributor

commented Jun 15, 2015

I stumbled upon this too. Pretty new to both Nim and, of course, the compilers source.
@boydgreenfield @zah - If anyone is up for pair-programming over TeamView or similar - I'm interested. Two knuckle heads reasoning about the code. Have only tinkered in the lexer and the parser up til now though.

@ozra

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2015

I could mention that I started debugging this one, but I simply can't make the time to finish it. Some one more clever or with more time is needed. If someone does, and any of what I've looked at can be of help (unsure), just ping me.

@dom96

This comment has been minimized.

Copy link
Member

commented Jun 27, 2015

@ozra pair hacking on Nim sounds like a fun idea

@dom96

This comment has been minimized.

Copy link
Member

commented Jun 27, 2015

@BigBoneDaddy "burly"?

@ozra

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2015

@BigBoneDaddy Well, to be honest, not much :-/. I figured if someone stumbled on something, I perhaps, maybe, possibly, could have an idea of some sort from my rumbling arounds.

I got it to match the type, but then the type vars didn't match, or I got it to work a bit further with another solution, but then there'd be an error in GC optimized collectors generation. So, I didn't really fully get a grip on the type graph, what should be and what shouldn't. What role the 'type-id's play and what their rules for uniqueness are. What's a miss and what's intended. It's not exactly documented at bible verse length... So, I finally had to give up (put food on the table kind of work and the garden takes their hours.)

@ozra

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2015

Haha, @BigBoneDaddy, I don't fit that description - except strong and robust perhaps, haha. Anyway, if you take on this bug it would be super, and I could try to make as much time as possible to help when possible.

@def-

This comment has been minimized.

Copy link
Member

commented Jan 24, 2018

Are you sure this is fixed? #4398 says "This doesn't finally fix #88"

@def- def- reopened this Jan 24, 2018

@zah zah added the Generics label Feb 9, 2018

@Araq Araq added High Priority and removed Feature labels Jul 1, 2018

@Araq

This comment has been minimized.

Copy link
Member Author

commented Jul 1, 2018

Newer version of this bug:

type
  TGen[T] = object of RootObj
    field: T

  TDerived[T] = object of TGen[T]
    nextField: T

proc doSomething[T](x: ref TGen[T]) =
  type
    Ty = ref TDerived[T]
  echo Ty(x).nextField

var
  x: ref TDerived[string]
new(x)
x.nextField = "test"

doSomething(x)

Araq added a commit that referenced this issue May 13, 2019

@Araq Araq closed this in 9ecb24e May 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.