Skip to content

Commit

Permalink
Allow SAM types to contain match alias refinements (scala#20092)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarter authored Apr 5, 2024
2 parents 3bf44f1 + 369ac1c commit 6a88601
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5892,7 +5892,7 @@ object Types extends TypeUtils {

/** Copy type aliases refinements to `toTp` from `fromTp` */
def withRefinements(toType: Type, fromTp: Type): Type = fromTp.dealias match
case RefinedType(fromParent, name, info: TypeAlias) if tp0.member(name).exists =>
case RefinedType(fromParent, name, info: AliasingBounds) if tp0.member(name).exists =>
val parent1 = withRefinements(toType, fromParent)
RefinedType(toType, name, info)
case _ => toType
Expand Down
32 changes: 32 additions & 0 deletions tests/pos/i20080.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

trait Zippable[-A, -B]:
type Out
def zip(left: A, right: B): Out

object Zippable extends ZippableLowPrio:
given append[A <: Tuple, B]: (Zippable[A, B] { type Out = Tuple.Append[A, B] }) =
(left, right) => left :* right

trait ZippableLowPrio:
given pair[A, B]: (Zippable[A, B] { type Out = (A, B) }) =
(left, right) => (left, right)


object Minimization:

trait Fun1:
type Out
def apply(x: Any): Out

type M[X] = X match
case String => X

def test[A] =

val _: Fun1 { type Out = M[A] } = new Fun1:
type Out = M[A]
def apply(x: Any): Out = ???

val _: Fun1 { type Out = M[A] } = x => ???

val _: Fun1 { type Out = A match {case String => A} } = x => ???

0 comments on commit 6a88601

Please sign in to comment.