-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Progress towards full SIP-23 support: correct inference for scala.Singleton, support for symbol literals #3565
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
Conversation
47009e0
to
bce112f
Compare
@milessabin The narrowing trick from scalac does not work in Dotty: scala> def narrow[T <: Singleton](x: T): T {} = x
def narrow[T <: Singleton](x: T): T
scala> narrow(1)
val res0: Int = 1 However, the following works in both scalac and dotty: scala> type Identity[T] = T
// defined alias type Identity = [T] => T
scala> def narrow[T <: Singleton](x: T): Identity[T] = x
def narrow[T <: Singleton](x: T): ([T] => T)[T]
scala> narrow(1)
val res1: ([T] => T)[1] = 1
scala> val b = res51
val b: ([T] => T)[1] = 1
scala> val c: 1 = b
val c: 1 = 1 (The fact that the dotty repl prints It might be useful to add a |
37cb879
to
2d7c60d
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.
Otherwise LGTM
@@ -315,6 +316,7 @@ object TastyFormat { | |||
final val STRINGconst = 77 | |||
final val IMPORTED = 78 | |||
final val RENAMED = 79 | |||
final val SCALASYMBOLconst = 80 |
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.
Why add Scala? I'd prefer we just called it SYMBOLconst
.
@@ -331,6 +333,8 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi | |||
ConstantType(Constant(readType())) | |||
case ENUMconst => | |||
ConstantType(Constant(readTermRef().termSymbol)) | |||
case SCALASYMBOLconst => |
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.
I don't think you need the duplication. SYMBOLconsts are simple types, so they should just occur in readSimpleType. I believe the duplication of CLASSconst and ENUMconst is also wrong and should be removed.
When a type variable is upper bounded by scala.Singleton, its instantiation should not be widened
This brings us closer to fully supporting SIP-23. Bump the version of TASTY to 1.1, adding support for symbol literals is a backwards-compatible change. The sip23-* tests are adapted from scala/scala#5310, the only difference is that we do not currently support the `T {}` trick to avoid widening when inferring types.
No description provided.