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

Disallow local term references in staged types #16362

Merged
merged 2 commits into from
Jan 23, 2023

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Nov 17, 2022

Fixes #15917
Fixes #16355

@@ -206,6 +206,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
tryHeal(prefix.symbol, tp, pos)
case _ =>
mapOver(tp)
case tp @ TermRef(NoPrefix, _) if !tp.symbol.isStatic && level > levelOf(tp.symbol) =>
Copy link
Member

Choose a reason for hiding this comment

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

why do we check level > here but level != in healTypeOfTerm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In healTypeOfTerm we are looking for terms that are used in other stages. Terms must be used at the same stage they are defined, hence the level !=.

For types the rules are a bit different. For types in general it is always safe to use the type in a previous stage and one needs a type Type[T] for generic types if it is used in a future stage. This is in general where the > comes in for type. But in this particular case, we have a type reference to a local variable that will not exist in the next stage and we cannot create a valid Type[T] for it. Therefore it emmits an error.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation, I think it'd be helpful to add something like that as a comment in the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to the comment.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

A more detailed comment would be helpful, otherwise LGTM.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.

@smarter smarter assigned nicolasstucki and unassigned smarter Jan 23, 2023
Co-authored-by: Guillaume Martres <smarter@ubuntu.com>
@nicolasstucki nicolasstucki merged commit eeb00d4 into scala:main Jan 23, 2023
@nicolasstucki nicolasstucki deleted the fix-16355 branch January 23, 2023 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants