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

Fixed generic inheritance dispatch #5

Merged
merged 1 commit into from
Oct 25, 2021

Conversation

beef331
Copy link
Contributor

@beef331 beef331 commented Oct 24, 2021

Using inherited generics does not dispatch properly and just takes the generic's base. This properly dispatches on the generic types so procs can overide based of inherited parameters. Making the following work:

type
  A[T] {.inheritable.} = object
  B = object of A[int]
  C = object of A[float]
proc doStuff(a: A[int]) = discard
proc doStuff(a: A[float) = discard
doStuff(B())
doStuff(C())

@@ -1412,6 +1412,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
let origF = f
var f = if prev == nil: f else: prev

if a.len > 0:
let skippedA = a.skipTypesOrNil({tyObject}) # Skips if it's inheriting from a generic
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One day when we have options in the compiler life will be grand.

@saem
Copy link
Collaborator

saem commented Oct 25, 2021

Could you add a few summary remarks as to what/why in the PR comment?

Hoping to have a useful for commit history over time.

@saem saem merged commit bfe544a into nim-works:devel Oct 25, 2021
@beef331 beef331 deleted the genInherDispatch branch October 25, 2021 04:02
@haxscramper haxscramper added this to the Sem phase refactoring milestone Nov 21, 2022
alaviss added a commit to alaviss/nimskull that referenced this pull request Apr 21, 2023
does app things

---
<!-- Note: section break (`---`) onwards is not in CI merge commit -->

## Notes for Reviewers
* leave additional context for reviewers
* maybe specific requests or areas of focus

<!--
Pull Request(PR) Help

Before Merge Ensure:
* title reads like a short changelog line entry
* code includes tests and is documented
* leave the source better than before, but split out big reformats

See contributor
(guide)[https://nim-works.github.io/nimskull/contributing.html]
for details, especially if you're new to this project.

Tips that make PRs easier:
* for big/impactful changes, start with chat/discussions to refine ideas
* refine the pull request message over time; don't have to nail it in
one go
* handle the single commit message requirement at the end of review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants