Skip to content

Commit

Permalink
Propagate hard vars when replacing Constraint params
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 12, 2023
1 parent 5290632 commit cc55175
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,9 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
}
if isRemovable(param.binder) then current = current.remove(param.binder)
current.dropDeps(param)
replacedTypeVar match
case replacedTypeVar: TypeVar if isHard(replacedTypeVar) => current = current.hardenTypeVars(replacement)
case _ =>
current.checkWellFormed()
end replace

Expand Down
32 changes: 32 additions & 0 deletions tests/pos/i18626.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
trait Random[F1[_]]:
def element[T1](list: Seq[T1]): F1[T1] = ???

trait Monad[F2[_]]:
def map[A1, B1](fa: F2[A1])(f: A1 => B1): F2[B1]

object Monad:
extension [F3[_]: Monad, A3](fa: F3[A3])
def map[B3](f: A3 => B3): F3[B3] = ???

sealed trait Animal
object Cat extends Animal
object Dog extends Animal

type Mammal = Cat.type | Dog.type
val mammals: List[Mammal] = ???

class Work[F4[_]](random: Random[F4])(using mf: Monad[F4]):
def result1: F4[Mammal] =
mf.map(fa = random.element(mammals))(a => a)

def result2: F4[Mammal] = Monad.map(random.element(mammals))(a => a)

import Monad.*

def result3: F4[Mammal] = random
.element(mammals)
.map { a =>
a // was: Type Mismatch Error:
// Found: (a : Animal)
// Required: Cat.type | Dog.type
}

0 comments on commit cc55175

Please sign in to comment.