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

Add TypedOrTest as super type of Typed in reflection #13362

Merged
merged 1 commit into from
Aug 26, 2021

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Aug 23, 2021

TypeOrTest can match or construct type tests or ascriptions x: T in expressions or patterns.
Unlike Typed, it contains a Tree instead of a Term which might be one of the patterns trees.

Fixes #12222

Alternative to part of #12200

@nicolasstucki nicolasstucki force-pushed the add-TypedOrTest branch 3 times, most recently from 0ad5be5 to 530326f Compare August 24, 2021 08:53
@nicolasstucki nicolasstucki added this to the 3.1.0 milestone Aug 24, 2021
@nicolasstucki nicolasstucki marked this pull request as ready for review August 24, 2021 10:05
@nicolasstucki nicolasstucki added the release-notes Should be mentioned in the release notes label Aug 24, 2021
@@ -345,6 +345,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
case x: (tpd.SeqLiteral & x.type) => Some(x)
case x: (tpd.Inlined & x.type) => Some(x)
case x: (tpd.NamedArg & x.type) => Some(x)
case x: (tpd.Typed & x.type) =>
TypedTypeTest.unapply(x) // Matches `Typed` but not `TypedOrTest`
case _ => if x.isTerm then Some(x) else None
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering about this type test (is my tree a term?) and isTerm (which is also "is my tree a term?"). I infer from the existing match that they don't always give the same answers. That seems wrong or at the very least confusing, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't always give the same answer. We aligned the term notation with the one in TastyFormat. The compiler does something slightly different in these cases. I will see if we can align the compiler with TASTy, that would simplify these runtime type tests.

TypeOrTest can match or construct type tests or ascriptions `x: T` in expressions or patterns.
Unlike `Typed`, it contains a `Tree` instead of a `Term` which might be one of the patterns trees.

Fixes scala#12222
@nicolasstucki nicolasstucki merged commit daeed81 into scala:master Aug 26, 2021
@nicolasstucki nicolasstucki deleted the add-TypedOrTest branch August 26, 2021 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes Should be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsoundness in the Reflection Typed
2 participants