Skip to content

improve as-seen-from with stables vals with existential types #185

Open
@retronym

Description

@retronym

Dotty allows:

trait Foo[A] { def source: A; def sink(a: A): Unit }
trait Test {
  val f: Foo[X] forSome { type X }
  f.sink(f.source)
}

I can get this compiling in Scalac with:

diff --git a/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala b/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
index df61d2e..4b7d000 100644
--- a/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
+++ b/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
@@ -602,7 +602,9 @@ private[internal] trait TypeMaps {
         else nextBase match {
           case NoType                         => loop(NoType, clazz.owner) // backstop for SI-2797, must remove `SingletonType#isHigherKinded` and run pos/t2797.scala to get here.
           case applied @ TypeRef(_, _, _)     => correspondingTypeArgument(classParam, applied)
-          case ExistentialType(eparams, qtpe) => captureSkolems(eparams) ; loop(qtpe, clazz)
+          case ExistentialType(eparams, qtpe) =>
+            if ((pre eq this.seenFromPrefix) && isStablePrefix) qtpe
+            else {captureSkolems(eparams) ; loop(qtpe, clazz) }
           case t                              => abort(s"$tparam in ${tparam.owner} cannot be instantiated from ${seenFromPrefix.widen}")
         }
       }

Is this sound? Is it general enough?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions