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

fix #15959 #15979

Closed
wants to merge 6 commits into from
Closed

fix #15959 #15979

wants to merge 6 commits into from

Conversation

cooldome
Copy link
Member

Please review the approach. My knowledge of generics is still lacking.
I have added typeFromExpr for subscript operator, but I was getting cannot Eval error from the vm in replaceTypeVarsTAux.

Because of this I have patched replaceTypeVarsTAux to call semExpr instead of semConstExpr and use semConstExpr only if needed. This step I am not sure about.

@cooldome cooldome requested review from zah and Araq November 15, 2020 12:30
@timotheecour
Copy link
Member

timotheecour commented Nov 15, 2020

this doesn't fix #15959, only a particular case. Commit + PR should be changed to refs #15959, many examples there still don't work.
But I don't think special casing subscript operator is a good idea, a general fix is needed otherwise you'll end up with lots of complexity to handle the other cases similarly.

typeFromExpr is indeed the proper fix, but it should be applied in the general case, perhaps as a catch-all.

@cooldome
Copy link
Member Author

cooldome commented Nov 16, 2020

I have tried catch all typeFromExpr, it creates a lot more problems than fixes.
Special casing for subscrit is required because sem has special case for it, if a[0] was a generic function call than special casing would not be required. BracketExpr remains special expression, so its type.

@cooldome
Copy link
Member Author

Test failure is unrelated

@timotheecour
Copy link
Member

either way, this still holds:

this doesn't fix #15959, only a particular case. Commit + PR should be changed to refs #15959, many examples there still don't work.

@@ -1513,6 +1513,9 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
result = n
else:
result = nil
of tyGenericParam:
result = n
result.typ = makeTypeFromExpr(c, n.copyTree)
Copy link
Member

Choose a reason for hiding this comment

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

That seems to be a bad idea, can't we add a better proc/syntax/interface to tyGenericParam. The [] is very overloaded already, seems to be recipe for desaster.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure I understand. If [] was a proc defined in system then this change wouldn't be required, but nkBracketExpr is still the special beast that is handled by its own rules. These rules don't handle tyGenericParam, hence the fix.

Another solution would be to define all missing procs in system.nim

proc `[]`[T: tuple](x: T, i: int): T {.magic: "XXX".}

Possibly others and then remove most of semSubscript and rely on operator overloading.
Not sure this change will be easy and go smoothly though.

Copy link
Member

@timotheecour timotheecour Nov 18, 2020

Choose a reason for hiding this comment

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

[] special rules indeed cause a lot of issues (eg #15911) and should be replaced by proper overloading (of possibly magic procs)

@stale
Copy link

stale bot commented Nov 18, 2021

This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Nov 18, 2021
@stale stale bot closed this Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Staled PR/issues; remove the label after fixing them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants