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

Regression with mixin and generics from 2.0.8 to version-2-0/version-2-2, fixed in devel #24163

Closed
tersec opened this issue Sep 23, 2024 · 5 comments
Labels
Needs Backporting/Fixed in Devel The issues can be solved via backporting

Comments

@tersec
Copy link
Contributor

tersec commented Sep 23, 2024

Description

type
  K = distinct int
  M = object

proc p(e: auto, T: type): T =
  mixin p
  p(e, result)

proc p[T](r: M, g: T) =
  when g is object:
    mixin p
    discard p(r, K)
  else:
    {.error: "u".}

proc p(_: M, _: K | K) = discard

Nim Version

Builds:
v2.0.8:

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

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

devel:

Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: a55c15c651b805c5eca4475f9845a57adf6cddef
active boot switches: -d:release

Does not build:
version-2-0:

Nim Compiler Version 2.0.9 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 27381cc60213e19aa34664176bd358ca5e45bd5a
active boot switches: -d:release

version-2-2:

Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 755307be61e4ee7b32c8354b2c303d04bdfc3a3e
active boot switches: -d:release

Current Output

/tmp/v.nim(17, 10) template/generic instantiation of `p` from here
/tmp/v.nim(7, 4) template/generic instantiation of `p` from here
/tmp/v.nim(14, 12) Error: u

Expected Output

No response

Known Workarounds

No response

Additional Information

Fixed in devel, so presumably there's something to backport from devel to version 2-0/version-2-2.

@metagn
Copy link
Collaborator

metagn commented Sep 23, 2024

Was caused by #23870 and fixed by #24144 @narimiran

@metagn metagn added the Needs Backporting/Fixed in Devel The issues can be solved via backporting label Sep 23, 2024
@narimiran
Copy link
Member

Was caused by #23870 and fixed by #24144 @narimiran

Thanks for the ping. Backported now. @tersec, it should be ok now (the example now works on my machine).

@tersec
Copy link
Contributor Author

tersec commented Sep 23, 2024

Was caused by #23870 and fixed by #24144 @narimiran

Thanks for the ping. Backported now. @tersec, it should be ok now (the example now works on my machine).

Well, I realized the repro I posted above somehow omitted the last line, so it always compiles. For reference, one example of how to complete it:

type
  K = distinct int
  M = object

proc p(e: auto, T: type): T =
  mixin p
  p(e, result)

proc p[T](r: M, g: T) =
  when g is object:
    mixin p
    discard p(r, K)
  else:
    {.error: "u".}

proc p(_: M, _: K | K) = discard
p(default(M), default(K))

and, obviously, that first p overload isn't used anymore, and

type
  K = distinct int
  M = object

proc p[T](r: M, g: T) =
  when g is object:
    mixin p
    discard p(r, K)
  else:
    {.error: "u".}

proc p(_: M, _: K | K) = discard
p(default(M), default(K))

exhibits the same pattern.

But haven't verified yet with new version-2-0.

@metagn
Copy link
Collaborator

metagn commented Sep 23, 2024

I noticed and forgot to mention it, that's what I used to check the issue

@narimiran
Copy link
Member

The fix is backported, I think this can be closed. (If not, please reopen)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Backporting/Fixed in Devel The issues can be solved via backporting
Projects
None yet
Development

No branches or pull requests

3 participants