Skip to content

Commit f3e8074

Browse files
committed
Allow for higher-kinded opaque types
1 parent d758b6c commit f3e8074

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,22 @@ object SymDenotations {
380380
case _ => unforcedDecls.openForMutations
381381
}
382382

383+
/** If this is an opaque type alias, mark it as Deferred with empty bounds
384+
* while storing the former right-hand side in an OpaqueAlias annotation.
385+
*/
383386
final def normalizeOpaque()(implicit ctx: Context) = {
387+
def abstractRHS(tp: Type): Type = tp match {
388+
case tp: HKTypeLambda => tp.derivedLambdaType(resType = abstractRHS(tp.resType))
389+
case _ => defn.AnyType
390+
}
384391
if (is(Opaque)) {
385-
addAnnotation(Annotation.OpaqueAlias(info.bounds.lo))
386-
setFlag(Deferred)
387-
info = TypeBounds.empty
392+
info match {
393+
case tp @ TypeAlias(alias) =>
394+
addAnnotation(Annotation.OpaqueAlias(alias))
395+
info = TypeBounds(defn.NothingType, abstractRHS(alias))
396+
setFlag(Deferred)
397+
case _ =>
398+
}
388399
}
389400
}
390401

tests/pos/opaque.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ object opaquetypes {
2121
}
2222
}
2323
}
24+
object usesites {
25+
import opaquetypes._
26+
import Logarithm.LogarithmOps // todo: drop
27+
val l = Logarithm(1.0)
28+
val l2 = Logarithm(2.0)
29+
val l3 = l + l2
30+
val d = l3.toDouble
31+
val l4: Logarithm = (1.0).asInstanceOf[Logarithm]
32+
}

0 commit comments

Comments
 (0)