Skip to content

Use canonical underlying type reference #10110

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

Merged

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@nicolasstucki nicolasstucki force-pushed the use-canonical-undelying-type branch from 40b8801 to 8afec66 Compare October 28, 2020 13:18
@nicolasstucki nicolasstucki marked this pull request as ready for review October 28, 2020 16:07
@@ -4,7 +4,7 @@ import scala.quoted._
object Test {
def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{
val y: t.Underlying = $x;
${loop[t.Underlying]( // error
${loop[t.Underlying](
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually crashing with an assertion failure at
8afec66#diff-b3069d0753da3a2c12847b53d12eaf5d5003af1d6e6438c84f1dd5f6ef6a668eL218.

This also happens on master.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not open an issue as the fix was straightforward.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

}

{
val s = '{Option.empty[${T}]} // works
val s = '{Option.empty[T.Underlying]} // works
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
val s = '{Option.empty[T.Underlying]} // works
val s = '{Option.empty[T]} // works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is equivalent but should not be changed to keep testing the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example, the second commit found the bug because I kept it as T.Underlying.

val r1 = '{Option.empty[T.Underlying]} // works
val r2 = '{Option.empty[List[T.Underlying]]} // works
val r3 = '{summon[Type[T.Underlying]]} // error: is not stable
val r4 = '{summon[T.Underlying <:< Any]} // error: is not stable
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little surprising that List[T.Underlying] works but summon[Type[T.Underlying]]] is an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one was subtle.

[error] (Test.this.given_Type_T : => quoted.Type[Test.this.T]) is not a valid type witness, since it is not an immutable path

The issue is that given Type[T] = getT is not stable. This is where I usually write given getT.type = getT to not lose the path in the given.

The other cases happen to work because we only referred to T.Underlying and never needed to head some type. This is the expected behavior.

else report.warning(msg, tree.srcPos)
// if sourceVersion.isAtLeast(`3.1-migration`) then
report.error(msg, tree.srcPos)
// else report.warning(msg, tree.srcPos)
Copy link
Contributor

Choose a reason for hiding this comment

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

So we decide to enforce it in M1? That's fine, just make sure it's not an accidental change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to revert this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted

@nicolasstucki nicolasstucki force-pushed the use-canonical-undelying-type branch from 8afec66 to a779493 Compare October 30, 2020 08:18
@nicolasstucki nicolasstucki merged commit 9ec34f8 into scala:master Oct 30, 2020
@nicolasstucki nicolasstucki deleted the use-canonical-undelying-type branch October 30, 2020 10:28
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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