-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Warn users on non canonical type references #9952
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
Warn users on non canonical type references #9952
Conversation
146bffc
to
fdd06df
Compare
@@ -1,6 +1,6 @@ | |||
import scala.quoted._ | |||
|
|||
def summonTypedType[T : Type](using QuoteContext): String = '[T] match { | |||
def summonTypedType[T : Type](using QuoteContext): String = Type[T] match { | |||
case '[Boolean] => "Boolean" | |||
case '[Byte] => "Byte" | |||
case _ => "Other" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems '[T]
is more symmetric here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, and that is why it should not be used. The syntactic symmetry is what lead to most conceptual misunderstandings of how Type works.
This constructor should also never be used explicitly and giving it a shorter alias does not help users avoid the explicit use.
It is also uncertain that the case '[...]
pattern will be kept. We might remove them and use only a single matching abstraction as we do with inline match
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the usage is bad, what about disallowing it in syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is my intent as I explain in #9486. This is a first step to help migration. We can drop the syntax later on once users have adapted. I would prefer to have at least one release with a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to bring this up in the meeting, as it's syntax related.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This specific case is a corner case that should be avoided. It should have been written explicitly as
def summonTypedType[T : Type](using QuoteContext): String = summon[Type[T]] match { ...
// or
def summonTypedType[T](using tp: Type[T])(using QuoteContext): String = tp match { ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rewrite this test to remove the '[Byte]
syntax?
fdd06df
to
16eeae3
Compare
16eeae3
to
d543a89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -1,6 +1,6 @@ | |||
import scala.quoted._ | |||
|
|||
def summonTypedType[T : Type](using QuoteContext): String = '[T] match { | |||
def summonTypedType[T : Type](using QuoteContext): String = Type[T] match { | |||
case '[Boolean] => "Boolean" | |||
case '[Byte] => "Byte" | |||
case _ => "Other" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rewrite this test to remove the '[Byte]
syntax?
d543a89
to
d88b066
Compare
Help users write the correct variant of the quoted type encoding. Explicit construction of a `scala.quoted.Type[_]` should be done with its constructor. Explicit construction of types in not encouraged as it should be created implicitly. Creating an `Type` explicitly is only useful for debugging purposes. Likewise, we encourage the use of the explicit inner type reference.
d88b066
to
580b6fd
Compare
I added |
The alternative approach does not look as nice as the previous version. Will it be simpler to do it using reflect API? Or, users should use |
We could add |
Just for consistency, if we remove the |
Not sure is we will remove This PR in combination with #10045 aims to make users of |
Help users write the correct variant of the quoted type encoding.
Explicit construction of a
scala.quoted.Type[_]
should be done with its constructor.Explicit construction of types in not encouraged as it should be created implicitly.
Creating an
Type
explicitly is only useful for debugging purposes.Likewise, we encourage the use of the explicit inner type reference.